The Swift-est way to build native mobile apps that connect to Salesforce.

Overview

Swiftly Salesforce

  

Swiftly Salesforce is the Swift-est way to build native mobile apps that connect to Salesforce:

Minimum Requirements

  • iOS 14.0
  • Swift 5.3
  • Xcode 12

Quick Start

Get up and running in a few minutes:

  1. Get a free Salesforce Developer Edition environment.
  2. Create a Connected App in your new environment. (Example)
  3. 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 query, insert, retrieve, update or delete Salesforce records using ConnectedApp's relevant convenience methods.

Or you could create your own struct that implements the Service protocol and overrides its default property implementations. Then use your custom service as an argument to ConnectedApp's go method.

Sample App

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.

Documentation

Swiftly Salesforce documentation

User Authorization

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 allowsLogin to 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

Comments
  • 'group by' count() soql fails in 9.0

    'group by' count() soql fails in 9.0

    SELECT activitydate, status, Count(Id) Cnt FROM task WHERE isdeleted = false GROUP BY activitydate, status

    used to work, now it fails with : Error: keyNotFound(CodingKeys(stringValue: "url", intValue: nil), Swift.DecodingError.Context(codingPath: [CodingKeys(stringValue: "records", intValue: nil), _JSONKey(stringValue: "Index 0", intValue: 0), RecordCodingKey(stringValue: "attributes", intValue: nil)], debugDescription: "No value associated with key CodingKeys(stringValue: "url", intValue: nil) ("url").", underlyingError: nil))

    bug 
    opened by perbrondum 26
  • I am using below custom API and getting below error:

    I am using below custom API and getting below error:

    The operation could not be completed. (SwiftlySalesforce.RequestError error 1.)

    Using: first { salesforce.apex(method: .post, path: path!, parameters: nil, body: jsonData, contentType: "application/json") }.then { result in }.catch { error in }

    question 
    opened by degreecloud 18
  • Salesforce login Page is not showing up

    Salesforce login Page is not showing up

    I have added swiftly salesforce through cocoa pods and successfully configured app delegate file but instead of opening salesforce login page on safari, app shows my rootViewcontroller. Please suggest what i should try?

    question 
    opened by degreecloud 15
  • Salesforce.identity fails when iOS time setting is a specific condition.

    Salesforce.identity fails when iOS time setting is a specific condition.

    Salesforce.identity() fails when iOS Setting Time 24-Hour Time is off ( iOS displays am/pm time when the mode is off) .

    This error doesn't occur iOS simulators and when iOS language is English. iOS language was Japanese when the error occcured.

    The URL below is a related document. https://developer.apple.com/library/content/qa/qa1480/_index.html

    struct Identity {
      public init(from decoder: Decoder) throws {
        ....
        // failed.
        self.lastModifiedDate = try container.decode(Date.self, forKey: .lastModifiedDate) 
      } 
    }
    
    investigating 
    opened by hmuronaka 13
  • Custom Branding login page not supported

    Custom Branding login page not supported

    • Login working fine when we using default login page • When we use custom branding login page • It loads the login url in SFSafariViewController properly, but after click on login its redirects me to chatter page in same window, which is incorrect flow. • In case of default login page, it redirects me to my application, which is correct flow. • For custom branding we are using vfx page in backend. • I need to implement custom branding login in my application and navigate to my application after click on login Kindly can you guys help me with this. Thanks in advance ...

    question investigating 
    opened by abhijeetkokane 10
  • Treat 403 errors differently when due to lack of API support or API request limit exceeded

    Treat 403 errors differently when due to lack of API support or API request limit exceeded

    For example, 403 error caused by Professional Edition without API should be handled differently (e.g. error exposed to end user) than other causes, which result in re-authentication and re-authorization via Salesforce-hosted form. See also Issue #27

    bug 
    opened by mike4aday 10
  • How to use SFPushNotificationManager in Swiftly

    How to use SFPushNotificationManager in Swiftly

    So I'm able to send a test push to the device from the Salesforce console... However, I believe I'm meant to use the SFPushNotificationManager to get the device token into the User object in salesforce.

    Is SFPushNotificationManager not available in SwiftlySalesforce. Will I have to use and auth with the SalesforceMobileSDK-iOS in order to do this?

    question 
    opened by helloniklas 10
  • organization() does not return organization info

    organization() does not return organization info

    Should the following not work? (a la identity()) first {
    salesforce.organization() }.then { (org) -> Promise in if let nameSpacePrefix = org.nameSpacePrefix { print("using namespaceprefix (nameSpacePrefix)") } }

    question 
    opened by ghost 9
  • Not able to open another URL of SF after opening login URL on Safari controller

    Not able to open another URL of SF after opening login URL on Safari controller

    Hi,

    I'm using swiftly salesforce to for login to salesforce account from my iPhone app using Swift 3.0. I have followed this SwiftlySalesforce link.

    Here swiftly salesforce replaces your rootviewController with SFSafariViewController. Once login is done it will replace safari view controller with your initial rootviewController. I'm able to get all details of user from which I have logged in. Now on my initial view which is my rootview, I want to show chatter page which usually comes after successful login on webview. But I'm getting login page again on webview.

    I think this is happening because the login seesion I'm getting from safari View controller is not getting to webview. Or is there any other issue?

    If anyone have worked on such requirement, or anyone could help me, please post your answers here. Your help is appritiated.

    Thank you, Ankita

    question 
    opened by NanostuffsTech 9
  • Authorization Not Working

    Authorization Not Working

    I am completely unsure why authorization is not working for me..

    Not working with example app or my integrated app.

    I am taken to the callbackURL, but then after that the safari view controller is not dismissed and the app does not retrieve the token.

    question 
    opened by aparente99 9
  • Query with date predicate fail

    Query with date predicate fail

    Simple Date SOQL statement fails in 9.0.6 "select name from account where lastmodifiedDate > 2023-01-01T12:00:00.000+0100"

    fails with: "Query Error : SalesforceError(code: "MALFORMED_QUERY", message: "\nlastmodifiedDate > 2023-01-01T12:00:00.000 0100\n ^\nERROR at Row:2:Column:48\nline 2:48 no viable alternative at character ' '", fields: nil)"

    testcase: `// Fails in 9.06 BETA with date format @available(iOS 15.0.0, *) private func simpleDateQuery() async throws { DB.salesforce.identity().sink(receiveCompletion: { (completion) in switch completion { case .finished: break case let .failure(error) : print("Failed to login. Error: (error)") } }) { identity in let userId = identity.userID

        let userSoql = "select name from account where lastmodifiedDate > 2023-01-01T12:00:00.000+0100"
      //  print(userSoql)
        DB.salesforce.query(soql: userSoql).sink(receiveCompletion: { (completion) in
            switch completion {
            case let .failure(error):
                testResults[8] = "simpleDateQuery, Failure"
                testErrors[8] = error
                print("Failed query(8) SFDC. Error: \(error)")
            case .finished:
                testResults[8] = "simpleDateQuery, Success"
                printOut()
            }
        }, receiveValue: { (userData : QueryResult<User>) in
            //
        }).store(in: &subscriptions)
    }.store(in: &subscriptions)
    

    }`

    bug 
    opened by perbrondum 8
Releases(v10.0.1)
Owner
Michael Epstein
@salesforce
Michael Epstein
iTunes Connect Library inspired by FastLane

Mothership iTunes Connect Library inspired by FastLane I wrote MotherShip for two reasons. love FastLane, but I am not proficient in Ruby. I wanted to

thecb4 74 Nov 3, 2022
Build Slack apps, in Swift

SlackKit: Slack Apps in Swift Description SlackKit makes it easy to build Slack apps in Swift. It's intended to expose all of the functionality of Sla

Peter Zignego 1k Dec 20, 2022
A Swift Framework build for the Ark Ecosystem

Introduction Overview SwiftyArk is a simple, lightweight framework for the Ark Ecosystem. SwiftyArk provides a simple wrapper for accessing Ark accoun

Andrew Walz 8 May 12, 2019
The best way to use the Zora API in your Swift projects.

ZoraKit The best way to use the Zora API in your Swift projects. Disclaimer This is still very much a work in progress, and is really a proof-of-conce

MBLA 6 Sep 23, 2022
Easy and powerful way to interact with VK API for iOS and macOS

Easy and powerful way to interact with VK API for iOS and macOS. Key features ?? It's not ios-vk-sdk ?? ?? One library for iOS and mac OS ?? ?? Fully

null 260 Dec 22, 2022
Wanikani-swift - Unofficial Swift client for the WaniKani API

WaniKani A Swift library and client for the WaniKani REST API. It currently supp

Aaron Sky 5 Oct 28, 2022
AWS Full Stack Swift with Apple CarPlay

This application demonstrates a full-stack Apple CarPlay app that uses Swift for both the UI and the backend services in AWS. The app accesses Lambda functions written in Swift and deployed from Docker images. The app accesses Amazon Location Service and a 3rd party weather api to display information in the vicinity of the user.

AWS Samples 100 Jan 6, 2023
A Swift wrapper for Foursquare API. iOS and OSX.

Das Quadrat Das Quadrat is Foursquare API wrapper written in Swift. Features Supports iOS and OSX. Covers all API endpoints. Authorization process imp

Constantine Fry 171 Jun 18, 2022
Pokeapi wrapper, written in Swift

PokemonKit What is this? PokemonKit is a swift wrapper for Pokeapi. PokemonKit use Alamofire and PromiseKit for async web requests handling. Usage imp

Continuous Learning 105 Nov 16, 2022
Unofficial GitHub API client in Swift

Github.swift ❤️ Support my apps ❤️ Push Hero - pure Swift native macOS application to test push notifications PastePal - Pasteboard, note and shortcut

Khoa 184 Nov 25, 2022
A swift SDK for Medium's OAuth2 API

Medium SDK - Swift A library to allow access to Medium API for any Swift iOS application. Features Medium.com authorization & token handling Login sta

null 11 Jan 22, 2022
A Twitter framework for iOS & OS X written in Swift

Getting Started Installation If you're using Xcode 6 and above, Swifter can be installed by simply dragging the Swifter Xcode project into your own pr

Matt Donnelly 2.4k Dec 30, 2022
👤 Framework to Generate Random Users - An Unofficial Swift SDK for randomuser.me

RandomUserSwift is an easy to use Swift framework that provides the ability to generate random users and their accompanying data for your Swift applic

Wilson Ding 95 Sep 9, 2022
Swift 3 framework for accessing data in Event Registry (http://eventregistry.org/)

PPEventRegistryAPI Swift 3 framework for accessing data in Event Registry (http://eventregistry.org/) Supported API calls Log In Get Event By Identifi

Pavel Pantus 8 Nov 1, 2016
Swift client for Unsplash

Unsplash API client written in Swift. Unsplash offers 2 APIs: Source API (unlimited requests) Official API JSON API (5000 requests / hour) JSON API is

Modo 188 Nov 12, 2022
An Elegant Spotify Web API Library Written in Swift for iOS and macOS

Written in Swift 4.2 Spartan is a lightweight, elegant, and easy to use Spotify Web API wrapper library for iOS and macOS written in Swift 3. Under th

Dalton Hinterscher 107 Nov 8, 2022
An Elegant Financial Markets Library Written in Swift

Notice As of May 20th, 2017, it appears that Yahoo is dropping support for a few features that BigBoard supports or there is an outage on their end ca

Dalton Hinterscher 66 Dec 7, 2022
Swift Wrapper For Bittrex API

BittrexApiKit Swift client for Bittrex api. It support all APIs with most recent changes. more info here let api = Bittrex(apikey: "api key", secretke

Saeid 8 Apr 5, 2021
iOS/macOS Cross-platform Ark-Ecosystem Framework in Swift | Powered by Ѧrk.io |

a macOS & iOS Swift Framework for Ark.io. What is ARKKit? ARKKit is wrapper for interacting with the Ark Ecosystem. It is written purely in Swift 4.0,

Simon 19 Jun 28, 2022