Swiftly Salesforce is the Swift-est way to build native mobile apps that connect to Salesforce:
- Written entirely in Swift.
- Very easy to install and update with Swift Package Manager.
- Built with Apple's Combine framework to simplify complex, asynchronous calls to the Salesforce REST API.
- Works great with SwiftUI, the modern, declarative way to build iOS apps.
- Manages the Salesforce user authorization flows automatically.
- Pair with Core Data for a complete offline mobile solution.
- Simpler and lighter alternative to the Salesforce Mobile SDK for iOS.
- See what's new in this release.
- iOS 14.0
- Swift 5.3
- Xcode 12
Get up and running in a few minutes:
- Get a free Salesforce Developer Edition environment.
- Create a Connected App in your new environment. (Example)
- Add the Swiftly Salesforce package to your Xcode project with URL https://github.com/mike4aday/SwiftlySalesforce.git.
Check out this screenshot for an example Connected App definition. Note that the checkbox for "Require Secret for Refresh Token Flow" should not be selected.
Most of your interactions with Swiftly Salesforce will be via the
ConnectedApp struct, which represents your Salesforce Connected App. For example, you could
delete Salesforce records using
ConnectedApp's relevant convenience methods.
Check out MySalesforceAccounts for a complete, working app that uses SwiftUI, Combine and Swiftly Salesforce to display the user's Salesforce account records. Though it's a relatively-trival app, it illustrates how to configure an app and quickly connect it to Salesforce. See especially MyAccountsLoader.swift, ContentView.swift and Salesforce.json.
Before you run the sample app, edit Salesforce.json and replace the temporary values for the consumer key and callback URL with those of your own Connected App.
Swiftly Salesforce will automatically manage all required Salesforce authorization flows. If Swiftly Salesforce already has a valid access token in its secure store, it will include that token in the header of every API request. If the token has expired and Salesforce rejects the request, then Swiftly Salesforce will attempt to refresh the access token without bothering the user to re-enter the username and password. If Swiftly Salesforce doesn't have a valid access token, or is unable to refresh it, then Swiftly Salesforce will direct the user to the Salesforce-hosted login form.
You could modify this default authorization behavior if you don't want your user interrupted by Salesforce's authentication form. Many methods have an argument,
allowsLogin, which is
true by default (example). But if you set
false, Swiftly Salesforce would attempt to refresh the token without interrupting the user, and if that attempt is unsuccessful the call would fail. The user would not be prompted for the username and password, and you could catch the resulting error and handle it as you see fit.
Questions, Suggestions & Bug Reports
- Open a GitHub issue
- Send me a direct message on Twitter @mike4aday
- Send me a message on LinkedIn in/mike4aday