RemoteSettings is a framework that helps you to fetch remote data and to store them into a specific data structure.
- iOS 8.0+
- Xcode 9.0+
- Swift 4.0+
You can use CocoaPods to install RemoteSettings. Add the following command to your Podfile:
pod 'RemoteSettings', '~> 1.0'
Then run pod install
. Use import RemoteSettings
to import the Framework into your SourceFiles.
Experimental: We also offer a Playground as documentation, check it out :). And make sure "Show Rendered Markdown" is active.
Let's assume we want to use the GitHub API to fetch information about the RemoteSettings project. More specific we want to store the url of the RemoteSettings repository for later usage.
let apiUrl = URL(string:"https://api.github.com/repos/tbointeractive/remotesettings")!
- Create a subclass of RemoteSettings
- Implement the method
open func update(_ data: Data) throws
and process the fetched data
After you gained your designated information from the data, we recommend you to store that as instance member of that subclass - Create an object of the subclass
SubclassOfRemoteSettings(remote: apiUrl)
- Use that object to fetch data by calling
public func update(finished: Completion?)
PseudoCode:
final class GitHubRemoteSettings: RemoteSettings {
var repoUrl: URL?
open override func update(_ data: Data) throws {
self.repoUrl = // parse data (in this case this is some json), extract the repoUrl and store in member variable
}
}
let remoteSettings = GitHubRemoteSettings(remote: apiUrl)
remoteSettings.update() { error in
// error handling
}
// after an update your designated data is stored to repoUrl
remoteSettings.repoUrl
JSONRemoteSettings is handy if you need to handle with JSON data, like we had to do in our previous section.
- Create a subclass of JSONRemoteSettings
- Implement the methods
open func update(_ data: [AnyHashable: Any]) throws
andopen func update(_ data: [Any]) throws
Those are the callbacks for your already parsed JSON data. Those methods are mutex exclusive, so eitherupdate(_ data: [AnyHashable: Any])
orupdate(_ data: [Any])
is called. - Create an object of the subclass
SubclassOfJSONRemoteSettings(remote: apiUrl)
- Use that object to fetch data by calling
public func update(finished: Completion?)
TBD 👩💻
TBD 🙆
TBD 🙋