All Projects → Swinject → Swinjectpropertyloader

Swinject / Swinjectpropertyloader

Licence: mit
Swinject extension to load property values from resources

Programming Languages

swift
15916 projects

Projects that are alternatives of or similar to Swinjectpropertyloader

Thememanager
ThemeManager is a lightweight library for application to switching themes. support more attributes and theme extensions. more easy and convenient to use.
Stars: ✭ 165 (+587.5%)
Mutual labels:  json, plist
Jsonj
A fluent Java API for manipulating json data structures
Stars: ✭ 42 (+75%)
Mutual labels:  json, plist
Python Benedict
dict subclass with keylist/keypath support, I/O shortcuts (base64, csv, json, pickle, plist, query-string, toml, xml, yaml) and many utilities. 📘
Stars: ✭ 204 (+750%)
Mutual labels:  json, plist
Countries States Cities Database
🌍 World countries, states, regions, provinces, cities, towns in JSON, SQL, XML, PLIST, YAML, and CSV. All Countries, States, Cities with ISO2, ISO3, Country Code, Phone Code, Capital, Native Language, Timezones, Latitude, Longitude, Region, Subregion, Flag Emoji, and Currency. #countries #states #cities
Stars: ✭ 1,130 (+4608.33%)
Mutual labels:  json, plist
Tbox
🎁 A glib-like multi-platform c library
Stars: ✭ 3,800 (+15733.33%)
Mutual labels:  json, plist
Json Chunks
streamable json encoder
Stars: ✭ 17 (-29.17%)
Mutual labels:  json
Spray Json
A lightweight, clean and simple JSON implementation in Scala
Stars: ✭ 917 (+3720.83%)
Mutual labels:  json
Acf 5 Pro Json Storage
Save ACF 5 Pro field groups as JSON within this plugin, rather than inside your theme.
Stars: ✭ 16 (-33.33%)
Mutual labels:  json
Json to dart
Library that generates dart classes from json strings
Stars: ✭ 836 (+3383.33%)
Mutual labels:  json
Ps Webapi
(Migrated from CodePlex) Let PowerShell Script serve or command-line process as WebAPI. PSWebApi is a simple library for building ASP.NET Web APIs (RESTful Services) by PowerShell Scripts or batch/executable files out of the box.
Stars: ✭ 24 (+0%)
Mutual labels:  json
Python Ripple Lib
Python client for the Ripple API
Stars: ✭ 23 (-4.17%)
Mutual labels:  json
Easy Mock Server
A mock server for json and mock template files
Stars: ✭ 22 (-8.33%)
Mutual labels:  json
Html2json
Lightweight library that converts a HTML webpage to JSON data using a template defined in JSON.
Stars: ✭ 18 (-25%)
Mutual labels:  json
Config Rs
⚙️ Layered configuration system for Rust applications (with strong support for 12-factor applications).
Stars: ✭ 915 (+3712.5%)
Mutual labels:  json
Design Resources
Resources I like to use while designing
Stars: ✭ 17 (-29.17%)
Mutual labels:  resources
Forma
Typespec based parsing of JSON-like data for Elixir
Stars: ✭ 23 (-4.17%)
Mutual labels:  json
Csharpjson
C# 编写的通用Json数据解析库
Stars: ✭ 16 (-33.33%)
Mutual labels:  json
Defiant.js
http://defiantjs.com
Stars: ✭ 907 (+3679.17%)
Mutual labels:  json
Html Table Cli
Create interactive tables from JSON on the command-line
Stars: ✭ 23 (-4.17%)
Mutual labels:  json
Sanest
sane nested dictionaries and lists for python
Stars: ✭ 19 (-20.83%)
Mutual labels:  json

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].