How to code and test custom offer code redemption in Swift and Xcode
![Oscar de la Hera Gomez](https://www.delasign.com/CDN/headshots/profile.webp)
![Three flowers that represent StoreKit, Swift and XCode side by side. Beneath them sits the text “Redeem Custom Offer Codes.”](https://www.delasign.com/CDN/images/How-to-code-and-test-StoreKit-custom-offer-codes-in-Swift.webp)
A step by step guide on implementing and testing code that enables customers to redeem custom offer codes for Auto-Renewable Subscriptions in an App.
The guide was made using our Free iOS StoreKit 2 Open Source project which is recommended for developers or business folk wishing to learn about how In-App Purchases or Subscriptions work and the code behind them.
The following walkthrough assumes that you have already setup StoreKit with an offering, have developed a UI that allows an app to display and buy products and have a custom offer code available to be used with an Auto-Renewable subscription.
Please consult the guides below to learn how to setup StoreKit, create a StoreKit offering, create custom offer codes, design a UI that considers all StoreKit scenarios or make StoreKit product purchases.
Step One: Implement the Utility
![A screenshot of Xcode showing the code snippet that’s available below.](https://www.delasign.com/CDN/images/Utility.webp)
In XCode, create a new file and paste in the code below.
We recommend that you place it under Utils/StoreKit.
Step Two: Implement the code
![A screenshot of Xcode showing the code snippet that’s available below.](https://www.delasign.com/CDN/images/Code_2023-03-26-182305_fehc.webp)
In your app, wherever you wish to allow users to redeem custom offer codes, add the code below.
Step Three: Verify
![A screenshot of the Redeem Custom Offer Code screen in iOS.](https://www.delasign.com/CDN/images/Redeem1920x1280.webp)
Run the app and test the functionality. It should pop up a modal similar to the one above.
After a successful purchase, confirm that the Subscription appears in the StoreKit with the offer showing in the Transaction details.
![A screenshot of the transaction in the StoreKit Transaction Manager.](https://www.delasign.com/CDN/images/Transaction-Manager_2023-03-26-182404_dxyk.webp)
Looking to learn more about developing apps with StoreKit 2?
Read our comprehensive development guide linked below to learn about all the secrets behind developing In-App Purchases and Subscriptions with StoreKit 2.