Using this framework you can read property lists embedded inside of a running executable as well as those of executables stored on disk. These types of executables are often Command Line Tools. Built-in support is provided for reading both embedded info and launchd property lists. Custom property list types can also be specified.
To see a runnable sample app using this framework, check out SwiftAuthorizationSample.
Property lists are returned as Data
instances. Usually
you'll want to deserialize using one of:
ProperyListDecoder
's
decode(_:from:)
to deserialize the Data
into a Decodable
PropertyListSerialization
's
propertyList(from:options:format:)
to deserialize the Data
into an NSDictionary
Decodable
When running inside an executable, decode a launchd property list into a custom Decodable
struct:
struct LaunchdPropertyList: Decodable {
let machServices: [String : Bool]
let label: String
private enum CodingKeys: String, CodingKey {
case machServices = "MachServices"
case label = "Label"
}
}
let data = try EmbeddedPropertyListReader.launchd.readInternal()
let plist = try PropertyListDecoder().decode(LaunchdPropertyList.self, from: data)
NSDictionary
For an external executable, deserialize an info property list as an NSDictionary
:
let executableURL = URL(fileUrlWithPath: <# path here #>)
let data = try EmbeddedPropertyListReader.info.readExternal(from: executableURL)
let plist = try PropertyListSerialization.propertyList(from: data,
options: .mutableContainersAndLeaves,
format: nil) as? NSDictionary
Decodable
Using BundleVersion
Decode an info property list, using BundleVersion
to decode the
CFBundleVersion
entry:
struct InfoPropertyList: Decodable {
let bundleVersion: BundleVersion
let bundleIdentifier: String
private enum CodingKeys: String, CodingKey {
case bundleVersion = "CFBundleVersion"
case bundleIdentifier = "CFBundleIdentifier"
}
}
let data = try EmbeddedPropertyListReader.info.readInternal()
let plist = try PropertyListDecoder().decode(InfoPropertyList.self, from: data)
link |
Stars: 13 |
Last commit: 1 year ago |
BundleVersion
could be initialized with values ending in a period; this did not match CFBundleVersion
semantics. Values such as 1.2.
now correctly fail to initialize.Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics