Information is a library that allows Swift to easily access Info.plist files.
I would like the framework to have the following features
- InformationStringKey makes it easy to identify keys
- Use the Information macro to easily retrieve values
- Validate that the key is valid before execution All of the above features have been realized: nestings that do not exist do not compile, and the macro reports known keys whose declared type does not match their documented value type as compile errors.
Basically, all you have to do is specify a predefined Key in the Information macro. By attaching this to a variable, you get the value you want to get.
import Information
@Information(.copyright) var copyright: String- Key can be given as a string as is, or you can pass any Key you like.
If the key may not exist in the Info.plist, declare the property as an optional type. Missing keys then return nil instead of stopping the program.
@Information(.displayName) var displayName: String?Keys can refer to values nested inside dictionaries and arrays. Child keys are chained with dot syntax, and array elements or domain names with subscripts. Keys carry their position in the hierarchy as a type parameter (InformationStringKey<Scope>), so only child keys that actually exist under the parent are available — a nesting that does not exist, such as .copyright.allowsArbitraryLoads, does not compile.
// NSAppTransportSecurity > NSAllowsArbitraryLoads
@Information(.appTransportSecurity.allowsArbitraryLoads) var allowsArbitraryLoads: Bool?
// CFBundleURLTypes > [0] > CFBundleURLSchemes
@Information(.urlTypes[0].urlSchemes) var urlSchemes: [String]?
// NSAppTransportSecurity > NSExceptionDomains > example.com > NSIncludesSubdomains
@Information(.appTransportSecurity.exceptionDomains["example.com"].includesSubdomains) var includesSubdomains: Bool?A parent key used on its own returns the whole nested dictionary, written as a concrete type. Because nesting does not change the set of value types, dictionaries nest as concrete types too, such as [String: [String: Bool]]. The value is checked against the written type at run time — a mismatch stops the program for non-optional properties and returns nil for optional ones.
@Information(.environment) var environment: [String: String]?
@Information(.appTransportSecurity.exceptionDomains) var exceptionDomains: [String: [String: Bool]]?Keys written as string literals are undefined keys, so nesting is unrestricted: the literal is a key path where dictionary keys are joined with . and array indices are written as [n]. A key that itself contains dots (such as a domain name) is written in brackets and taken as-is.
@Information("NSAppTransportSecurity.NSAllowsLocalNetworking") var allowsLocalNetworking: Bool
@Information("CFBundleURLTypes[0].CFBundleURLSchemes") var urlSchemes: [String]
@Information("NSAppTransportSecurity.NSExceptionDomains[example.com]") var exceptionDomain: [String: Bool]?You can add it to your project using the Swift Package Manager To add Information to your Xcode project, select File > Add Package Dependancies... and find the repository URL:
https://github.com/KC-2001MS/Information.git.
See CONTRIBUTING.md if you want to make a contribution.
Documentation on the Information framework can be found here.
This library is released under Apache-2.0 license. See LICENSE for details.
If you would like to make a donation to this project, please click here. The money you give will be used to improve my programming skills and maintain the application.

Pay by PayPal