Last modified January 21, 2019 by Shelly Wolfe

Integrating the iOS SDK using Swift

In iOS, developers have the option to develop in either Objective-C, which supports most iOS versions, and Swift, which is becoming more widely used in iOS development. While the Swrve iOS SDK includes a number of Objective-C files, Apple has made it easy to use both Swift and Objective-C in the same project.

Integrating the iOS SDK using Swift

For instructions on how to integrate the iOS SDK into a Swift project, see the iOS integration guide.

Compatibility across language and OS version

Depending on the language and integration method used and the iOS version(s) your app supports, you may have compatibility issues with different iOS versions. Swrve currently supports two methods of integration:

  • Manually including the SDK as part of your Project.
  • Using CocoaPods as the dependency manager.

Coupled with the language used, the following combinations are possible:

  • Objective-C with CocoaPods
  • Objective-C with SDK included in project
  • Swift with CocoaPods
  • Swift with SDK included in project

The following sections describe issues that can occur in each combination and the workarounds available.

Objective-C with CocoaPods or with SDK in project

These are the most heavily tested and supported configurations in iOS. There are no integration issues at this time.

Swift with CocoaPods

CocoaPods forces the use of frameworks with Swift. When using a framework, the bundle and other compilation properties default to the main project. As a result, when you reference assets or frameworks in your code, the compiler assumes it’s in the main bundle. Therefore, you need to ensure that the correct bundle is referenced when loading these assets.

The assets issue is fixed in iOS SDK 4.5.2. For more information, see the iOS SDK release notes.

Swift with SDK in project

There are no major integration issues if you add the SDK directly to your Swift project. However, if you add extra imports to the Bridging-Header.h file, the appropriate files aren’t added to the SwrveSDK.h file to enable calls to the Message Center SwrveBaseCampaign object. As a workaround, add #import SwrveBaseCampaign.h to the bridging header. This issue is fixed in iOS SDK 4.5.2. For more information, see the iOS SDK release notes.