TestsTested | ✓ |
LangLanguage | SwiftSwift |
License | MIT |
ReleasedLast Release | Sep 2017 |
SwiftSwift Version | 4.0 |
SPMSupports SPM | ✓ |
Maintained by Nuno Manuel Dias.
InfoKit provides Strongly Typed access to the Info.plist with less than 60 lines of code, while leveraging Swift 4's powerful Codable capabilities.
Installation >> instructions
<<
Define a Codable with the properties you wish to access from the project's bundle Info.plist file.
struct Info: Codable {
let baseUrl: String
let staticUrl: String
}
And read the Info.plist into the Info
struct:
// Define a Plist
let plist = Plist<Info>()
// Decode it
let info = plist.decode()
// Then access it's properties
info?.baseUrl // http://debug.InfoKit.local
info?.staticUrl // http://debug.static.InfoKit.local
If no resource or bundle is specified in the initializer of the Plist
class, then InfoKit
will default to the Main Bundle's Info.plist file defined in the Project's Build Settings.
init(_ resource: String? = nil, in bundle: Bundle = Bundle.main)
Because of this, you can provide multiple Info.plist files for different configurations and still get the desired results. See the provided iOS Example project in action.
For convenience, InfoKit
will also provide access to custom .plist files. Let's say you included a ProductIDs.plist file. Start by defining the struct with it's respective properties.
struct Products: Codable {
let foo: String
let bar: String
}
Define a Plist
, and this time, specify the resource name. e.g. ProductIDs
let plist = Plist<Products>("ProductIDs") // Reads `ProductIDs.plist`
let products = plist.decode()
products?.foo // com.InfoKit.foo
products?.bar // com.InfoKit.bar
Remember, user provided property lists must be copied into the bundle, so make sure to set it's
Target Membership
.
InfoKit will default to the Main Bundle, however, you can specify the bundle, if needed:
Plist<Products>("ProductIDs", in: bundle)
InfoKit is released under the MIT license. See LICENSE for details.
Chinese is the #1 spoken language in the world and I'd love to have InfoKit be more inclusive, unfortunately I don't speak Chinese. If you know chinese, and would like to help out, please see issue #1
Thank you