0001 // 0002 // PropertyLoaderType.swift 0003 // Swinject 0004 // 0005 // Created by mike.owens on 12/6/15. 0006 // Copyright © 2015 Swinject Contributors. All rights reserved. 0007 // 0008 0009 import Foundation 0010 0011 0012 /// The PropertyLoaderType protocol defines an interface for loading properties from the applications 0013 /// bundle that can 0014 public protocol PropertyLoaderType{ 0015 0016 /// Will load the properties from the application bundle and return the properties dictionary containing 0017 /// the key-value pairs of the properties 0018 /// 0019 /// - returns: the key-value pair properties 0020 func load
Assembler.swift:43 public init(assemblies: [AssemblyType], propertyLoaders: [PropertyLoaderType]? = nil, container: Container? = Container()) throws {Assembler.swift:59 public init(assemblies: [AssemblyType], parentAssembler: Assembler?, propertyLoaders: [PropertyLoaderType]? = nil) throws {Assembler.swift:101 public func applyPropertyLoader(propertyLoader: PropertyLoaderType) throws {Container.swift:103 public func applyPropertyLoader(loader: PropertyLoaderType) throws {JsonPropertyLoader.swift:67 extension JsonPropertyLoader: PropertyLoaderType {PlistPropertyLoader.swift:35 extension PlistPropertyLoader: PropertyLoaderType {() throws -> [String:AnyObject] 0021 } 0022 0023 /// Helper function to load the contents of a bundle resource into a string. If the contents do not exist we will 0024 /// we will simply return nil to allow builds to specify optional property files. This is helpful for projects 0025 /// that white label an application that have properties that may or may not be set from a top level project. 0026 /// 0027 /// - Parameter bundle: the bundle where the resource exists 0028 /// - Parameter withName: the name of the resource to load (e.g. if resource is properties.json then this is properties) 0029 /// - Parameter ofType: the type of resource to load (e.g. json) 0030 /// 0031 /// - Returns: the contents of the resource as a string or nil if it does not exist 0032 func loadStringFromBundle
Container.swift:104 let props = try loader.load()(bundle: NSBundle, withName name: String, ofType type: String) throws -> String { 0033 if let resourcePath = bundle.pathForResource(name, ofType: type) { 0034 return try String(contentsOfFile: resourcePath) 0035 } 0036 throw PropertyLoaderError.MissingResource(bundle: bundle, name: name) 0037 } 0038 0039 /// Helper function to load the contes of a bundle resource into data. If the contents do not exist 0040 /// we will simply return nil to allow builds to specify optional property files. This is helpful for projects 0041 /// that white label an application that have properties that may or may not be set from a top level project. 0042 /// 0043 /// - Parameter bundle: the bundle where the resource exists 0044 /// - Parameter withName: the name of the resource to load (e.g. if resource is properties.json then this is properties) 0045 /// - Parameter ofType: the type of resource to load (e.g. json) 0046 /// 0047 /// - Returns: the contents of the resource as a data or nil if it does not exist 0048 func loadDataFromBundle
JsonPropertyLoader.swift:69 let contents = try loadStringFromBundle(bundle, withName: name, ofType: "json")(bundle: NSBundle, withName name: String, ofType type: String) throws -> NSData { 0049 if let resourcePath = bundle.pathForResource(name, ofType: type) { 0050 if let data = NSData(contentsOfFile: resourcePath) { 0051 return data 0052 } 0053 throw PropertyLoaderError.InvalidResourceDataFormat(bundle: bundle, name: name) 0054 } 0055 throw PropertyLoaderError.MissingResource(bundle: bundle, name: name) 0056 } 0057
PlistPropertyLoader.swift:37 let data = try loadDataFromBundle(bundle, withName: name, ofType: "plist")