0001 // 0002 // PlistPropertyLoader.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 PlistPropertyLoader will load properties from plist resources 0013 final public class PlistPropertyLoader{ 0014 0015 /// the bundle where the resource exists (defualts to mainBundle) 0016 private let bundle
PlistPropertyLoader.swift:35 extension PlistPropertyLoader: PropertyLoaderType {: NSBundle 0017 0018 /// the name of the JSON resource. For example, if your resource is "properties.json" then this value will be set to "properties" 0019 private let name
PlistPropertyLoader.swift:29 self.bundle = bundle!PlistPropertyLoader.swift:37 let data = try loadDataFromBundle(bundle, withName: name, ofType: "plist")PlistPropertyLoader.swift:40 throw PropertyLoaderError.InvalidPlistFormat(bundle: bundle, name: name): String 0020 0021 /// 0022 /// Will create a plist property loader 0023 /// 0024 /// - parameter bundle: the bundle where the resource exists (defaults to mainBundle) 0025 /// - parameter name: the name of the JSON resource. For example, if your resource is "properties.plist" 0026 /// then this value will be set to "properties" 0027 /// 0028 public init(bundle: NSBundle? = .mainBundle(), name: String) { 0029 self.bundle = bundle! 0030 self.name = name 0031 } 0032 } 0033 0034 // MARK: - PropertyLoadable 0035 extension PlistPropertyLoader: PropertyLoaderType { 0036 public func load() throws -> [String:AnyObject] { 0037 let data = try loadDataFromBundle(bundle, withName: name, ofType: "plist") 0038 let plist = try NSPropertyListSerialization.propertyListWithData(data, options: .Immutable, format: nil) 0039 guard let props = plist as? [String:AnyObject] else { 0040 throw PropertyLoaderError.InvalidPlistFormat(bundle: bundle, name: name) 0041 } 0042 return props 0043 } 0044 } 0045
PlistPropertyLoader.swift:30 self.name = namePlistPropertyLoader.swift:37 let data = try loadDataFromBundle(bundle, withName: name, ofType: "plist")PlistPropertyLoader.swift:40 throw PropertyLoaderError.InvalidPlistFormat(bundle: bundle, name: name)