iOS Native - 3.x to 4.x Migration
Read the migration blog post for more information about why we made the switch from Objective-C to Swift.
View the iOS SDK Reference documentation here →.
Migrating from Objective-C to Swift required a number of API changes, but we feel that the changes resulted in the SDK having a more natural feel for developers.
Xcode version requirements and updated deployment targets
purchases-ios
v4 requires using Xcode 13.2 or newer. It also updates the minimum deployment targets for iOS, macOS and tvOS.
Minimum deployment targets
v3 | v4 | |
---|---|---|
iOS | 9.0 | 11.0 |
tvOS | 9.0 | 11.0 |
macOS | 10.12 | 10.13 |
watchOS | 6.2 | 6.2 (unchanged) |
Migration Steps
To start us off, our framework name changed from Purchases
to RevenueCat
! 😻 You'll now need to explicitly import RevenueCat
instead of Purchases
.
1. Update Framework references
Swift
Before | After |
---|---|
import Purchases | import RevenueCat |
Objective-C
Before | After |
---|---|
@import Purchases; | @import RevenueCat; |
1.1 Update Swift Package Manager dependency (if needed)
Select your target in Xcode, then go to Build Phases, and ensure that your target's Link Binary with Libraries
section references RevenueCat
, and remove the reference to Purchases
if it was still there.
Before | After |
---|---|
link binary with libraries before | link binary with libraries after |
Note:
Due to an Xcode bug, you might run into a Workspace Integrity error after upgrading, with a message that looks like
"Couldn't load project PurchaseTester"
.
If this happens, you can fix it with the following steps:
- In Xcode, go to Product -> Clean Build Folder
- Quit and re-open Xcode
1.2 Update CocoaPods dependency (if needed)
In your Podfile, update the reference to the Pod from Purchases
to RevenueCat
. Don't forget to run pod update
after saving the Podfile.
Before | After |
---|---|
pod 'Purchases' | pod 'RevenueCat' |
1.3 Update Carthage Framework (if needed)
1.3.1 Using XCFrameworks (recommended)
Select your target in Xcode, then go to Build Phases, and ensure that your target's Link Binary with Libraries
section
references RevenueCat
, and remove the reference to Purchases
if it was still there.
Do the same with the Embed Frameworks section.
Before | After |
---|---|
link binary with libraries before | link binary with libraries after |
embed frameworks before | embed frameworks after |
1.3.2 Using Platform-specific frameworks
We highly recommend moving into XCFrameworks, since these have a simpler setup and prevent compatibility issues with multi-platform setups.
Carthage has a migration guide to move into XCFrameworks available here.
After migrating into XCFrameworks, follow the steps outlined in 1.3.1 to set up the RevenueCat.xcframework
.
If you can't move into XCFrameworks, you will still need to update the Link Binary with Libraries
phase as outlined
in 1.3.1 (only using a .framework
instead of .xcframework
).
After that, update the your input.xcfilelist
and output.xcfilelist
for the Run Script phase of Carthage frameworks,
replacing Purchases.framework
with RevenueCat.framework
.
2. Update code references
2.1 Automatic Migration
When building your project using v4, Xcode should automatically provide one-click fixes methods and types that have been renamed. For the most part, the migration should be doable by just building and applying Xcode's automatic fix-its when they pop up.
If you see any issues or new APIs that fix-its didn't cover, we'd appreciate bug reports!
2.2 Update references to Purchases.foo
to RevenueCat.foo
You might run into compilation errors with a message like Error:
'_' is not a member type of class 'RevenueCat.Purchases'`.
The reason is that the class Purchases
is no longer the parent of classes such as Offerings
.
You should reference classes directly or as a child of RevenueCat
, e.g. RevenueCat.Offerings
instead of Purchases.Offerings
. You can also omit the framework entirely, i.e.: just using Offerings
directly.
2.3 Import StoreKit (if needed)
Our V3 SDK automatically imported StoreKit
whenever you did import Purchases
. Due to Swift limitations, our
V4 SDK doesn't do this automatically.
So if you're referencing StoreKit types directly, you might need to add
import StoreKit
in Swift, and @import StoreKit;
in Objective-C.