Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/iamjono/Swifty-pList
A Swift 3 pList library. Reads & writes pLists for configurations
https://github.com/iamjono/Swifty-pList
Last synced: 2 months ago
JSON representation
A Swift 3 pList library. Reads & writes pLists for configurations
- Host: GitHub
- URL: https://github.com/iamjono/Swifty-pList
- Owner: iamjono
- Created: 2016-09-13T14:01:21.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-09-13T14:52:44.000Z (over 8 years ago)
- Last Synced: 2024-11-13T10:59:58.947Z (2 months ago)
- Language: Swift
- Homepage:
- Size: 10.7 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
- TheList - Swifty-pList - A Swift 3 pList library. Reads & writes pLists for server side configuration. (Server Side Utilities / Configuration)
README
# Swifty-pList
A Swift 3 pList library. Reads & writes pLists for server side configuration.
Plist files can be used for maintaining system specific settings such as database names, credentials, api keys, access tokens.
It makes no sense to include these in compiled binaries as they will vary between development, staging and deployment environments,
or between distributions.### Setup
Include the Swifty-pList dependancy in your project's Package.swift file:
``` swift
.Package(url: "https://github.com/iamjono/Swifty-pList.git", majorVersion: 0, minor: 1)
```After changing your Package.swift file, remember to rebuild your Xcode project:
```
swift package generate-xcodeproj
```Open your project, and add a new pList file, and add the property key-value pairs in the same way as is seen in the example
[ApplicationConfiguration.plist](https://github.com/iamjono/Swifty-pList/blob/master/ApplicationConfiguration.plist).In the "Build Phases" for your target binary, add a "Copy Files" phase if one does not already exist.
Add your plist file to the file list, with a destination of "Resources".
When you build your project within Xcode this plist file will be copied next to your executable binary.When deploying on a server, make sure the plist file is in the same relative position, and change the values to those appropriate to the system.
### Example usage:
``` swift
func GetAPIKey() -> AppCredentials {
var creds = AppCredentials()
if let plist = Plist(name: "ApplicationConfiguration") {let dict = plist.getMutablePlistFile()!
creds.clientid = dict["clientid"] as! String
creds.clientsecret = dict["clientid"] as! Stringif creds.clientid.characters.count > 0 {
return creds
} else {
print("No API Key")
}
} else {
print("Unable to get Plist")
}
return creds
}func GetAPIToken() -> String {
var token = ""
if let plist = Plist(name: "ApplicationConfiguration") {let dict = plist.getMutablePlistFile()!
token = dict["token"] as! String
if token.characters.count > 0 {
return token
} else {
print("No API Key")
}
} else {
print("Unable to get Plist")
}
return token
}
```