Swinjectpropertyloader

Swinject extension to load property values from resources
Alternatives To Swinjectpropertyloader
Project NameStarsDownloadsRepos Using ThisPackages Using ThisMost Recent CommitTotal ReleasesLatest ReleaseOpen IssuesLicenseLanguage
Yq9,381703 days ago126July 12, 2023100mitGo
yq is a portable command-line YAML, JSON, XML, CSV, TOML and properties processor
Fast Json Stringify3,2527471675 days ago145August 02, 202321mitJavaScript
2x faster than JSON.stringify()
Jsonmapper1,508702219a month ago38April 09, 20234osl-3.0PHP
Map nested JSON structures onto PHP classes
Dynamic_widget1,353319 months ago29May 19, 202243apache-2.0Dart
A Backend-Driven UI toolkit, build your dynamic UI with json, and the json format is very similar with flutter widget code.
Jackson Annotations98229,1854,84312 days ago129May 26, 202212apache-2.0Java
Core annotations (annotations that only depend on jackson-core) for Jackson data processor
Sleekdb779475 months ago35October 10, 202129mitPHP
Pure PHP NoSQL database with no dependency. Flat file, JSON based document database.
Dynamicjson703
a year ago6January 16, 20193mitSwift
Access JSON properties dynamically like JavaScript using Swift 4.2's new @dynamicMemberLookup feature
Realm Json679
146 years ago22January 13, 201631mitObjective-C
A concise Mantle-like way of working with Realm and JSON.
Jsoncodable606
193 years ago6November 08, 201624mitSwift
Hassle-free JSON encoding and decoding in Swift
Postcss Custom Properties60132 years ago2June 18, 202043mitJavaScript
Use Custom Properties in CSS
Alternatives To Swinjectpropertyloader
Select To Compare


Alternative Project Comparisons
Readme

SwinjectPropertyLoader

Build Status Carthage compatible CocoaPods Version License Platform Swift Version

SwinjectPropertyLoader is an extension of Swinject to load property values from resources that are bundled with your application or framework.

Requirements

  • iOS 8.0+ / Mac OS X 10.10+ / watchOS 2.0+ / tvOS 9.0+
  • Swift 2.2 or 2.3
    • Xcode 7.0+
  • Swift 3.0.x
    • Xcode 8.0+
  • Carthage 0.18+ (if you use)
  • CocoaPods 1.1.1+ (if you use)

Installation

Swinject is available through Carthage or CocoaPods.

Carthage

To install Swinject with Carthage, add the following line to your Cartfile.

github "Swinject/Swinject" ~> 2.0.0
github "Swinject/SwinjectPropertyLoader" ~> 1.0.0

Then run carthage update --no-use-binaries command or just carthage update. For details of the installation and usage of Carthage, visit its project page.

CocoaPods

To install Swinject with CocoaPods, add the following lines to your Podfile.

source 'https://github.com/CocoaPods/Specs.git'
platform :ios, '8.0' # or platform :osx, '10.10' if your target is OS X.
use_frameworks!

pod 'Swinject', '~> 2.0.0'
pod 'SwinjectPropertyLoader', '~> 1.0.0'

Then run pod install command. For details of the installation and usage of CocoaPods, visit its official website.

Properties

Properties are values that can be loaded from resources that are bundled with your application/framework. Properties can then be used when assembling definitions in your container.

There are 2 types of support property formats:

  • JSON (JsonPropertyLoader)
  • Plist (PlistPropertyLoader)

Each format supports the types specified by the format itself. If JSON format is used then your basic types: Bool, Int, Double, String, Array and Dictionary are supported. For Plist, all types supported by the Plist are supported which include all JSON types plus NSDate and NSData.

JSON property files also support comments which allow you to provide more context to your properties besides your property key names. For example:

{
    // Comment type 1
    "foo": "bar",

    /* Comment type 2 */
    "baz": 100,

    /**
     Comment type 3
     */
    "boo": 30.50
}

Loading properties into the container is as simple as:

let container = Container()

// will load "properties.json" from the main app bundle
let loader = JsonPropertyLoader(bundle: .mainBundle(), name: "properties")

try! container.applyPropertyLoader(loader)

Now you can inject properties into definitions registered into the container.

Consider the following definition:

class Person {
    var name: String!
    var count: Int?
    var team: String = ""
}

And let's say our properties.json file contains:

{
    "name": "Mike",
    "count": 100,
    "team": "Giants"
}

Then we can register this Service type with properties like so:

container.register(Person.self) { r in
    let person = Person()
    person.name = r.property("name")
    person.count = r.property("count")
    person.team = r.property("team")!
}

This will resolve the person as:

let person = container.resolve(Person.self)!
person.name // "Mike"
person.count // 100
person.team // "Giants"

Properties are available on a per-container basis. Multiple property loaders can be applied to a single container. Properties are merged in the order in which they are applied to a container. For example, let's say you have 2 property files:

{
    "message": "hello from A",
    "count": 10
}

And:

{
    "message": "hello from B",
    "timeout": 4
}

If we apply property file A, then property file B to the container, the resulting property key-value pairs would be:

message = "hello from B"
count = 10
timeout = 4

As you can see the message property was overridden. This only works for first-level properties which means Dictionary and Array are not merged. For example:

{
    "items": [
        "hello from A"
    ]
}

And:

{
     "items": [
        "hello from B"
     ]
}

The resulting value for items would be: [ "hello from B" ]

Contributors

SwinjectPropertyLoader has been originally written by Mike Owens.

License

MIT license. See the LICENSE file for details.

Popular Properties Projects
Popular Json Projects
Popular Configuration Management Categories
Related Searches

Get A Weekly Email With Trending Projects For These Categories
No Spam. Unsubscribe easily at any time.
Swift
Json
Types
Properties
Plist