- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
Optimizely iOS SDK and Swift
Optimizely iOS SDK and Swift
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report
Hi,
We want to use Optimizely SDK in our iOS app. However, our app is written in Swift programing language.
1. Does optimizely SDK support the Swift Programming Language?
2. If so, is there a guide that anyone can point me to that shows how to configure and use optimizely withing a Swift project. The main problem I am facing is that I cannot do the
#ifdef DEBUG
[Optimizely enableEditor];
#endif
[Optimizely startOptimizelyWithAPIToken:
@"AAMseu0AR2oTE_hzbXQBNc3e6g7hau2D~xxxxxxxxxxx"
launchOptions:launchOptions];
within the Swit app.
Cheers,
Sam
Re: Optimizely iOS SDL and Swift
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report
Hi Sam!
The Optimizely SDK does in fact support Swift, and the quickest method to get this working would be to use the bridging method as described here.
You will have to add the Bridging Header, and since you already have an existing class, make sure to add it to your "<YourProject>-Bridging-Header.h" file as described in step five of the guide.
Don't hesitate to follow up with me personally if you run into any issues.
Cheers,
Paul
Re: Optimizely iOS SDL and Swift
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report
Hi Sam -
I wanted to make sure you were successful with this process, so please don't forget to modify your Bridging Header file by adding the following:
#import <Foundation/Foundation.h>
#import <UIKit/UIKit.h>
#import <Optimizely/Optimizely.h>
as well as:
Optimizely.enableEditor();
Optimizely.startOptimizelyWithAPIToken("yourtokenhere", launchOptions: launchOptions);
in your swift delegate.
That should do the trick
Paul
Re: Optimizely iOS SDL and Swift
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report
Re: Optimizely iOS SDL and Swift
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report
What is the syntax to get this bit of Obj C code in Swift: OptimizelyVariableKeyForNumber(myGravityVariable, @(9.8));
I cant seem to set a Variable key in Swift.
Cheers,
Sam
Re: Optimizely iOS SDL and Swift
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report
Launch screens may not use user defined runtime attributes.
I managed to circumvent it by deleting the launchscreen but that's not really what I want to do.
Re: Optimizely iOS SDL and Swift
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report
Since the release of iOS8 - you can now use a storyboard scene in place of your app’s launch images. This allowed the native "LaunchScreen.xib" file to be tagged with an OptimizelyId and therefore throw an exception. Be sure to remove the OptimizelyID from its runtime attribute and the error will be gone

Re: Optimizely iOS SDL and Swift
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report
Re: Optimizely iOS SDL and Swift
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report
You'll want to run our preparenibs script once and be sure to remove the OptimizelyId from your launch screen before compiling. Let me know if that takes care of the error - if not, we can take this offline and I'd be glad to take care of this for you.
Re: Optimizely iOS SDL and Swift
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report
Re: Optimizely iOS SDL and Swift
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report
What is the syntax to get this bit of Obj C code in Swift: OptimizelyVariableKeyForNumber(myGravityVariable, @(9.8));
I cant seem to set a Variable key in Swift.
Cheers,
Sam
Re: Optimizely iOS SDL and Swift
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report
You have definitely not been ignored! I will be sending you an email shortly with more details on Swift compatibility.
Cheers,
Paul
Re: Optimizely iOS SDL and Swift
- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report
I created an example that shows how to use Optimizely and some advanced features in Swift:
https://github.com/IAmMalte/swift-example-optimizely
Extensive readme will follow later today.
Re: Optimizely iOS SDL and Swift
[ Edited ]- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report
Hi shorty and Sam,
Thank you so much for your contribution @shorty. One of my team members will be in contact with you shortly to talk about sending you over some swag
@sampathd - Thank you for bringing these issues to our attention! As we are still in beta and developing our SDK; Swift compatibility is definitely in our radar and is receiving attention. The method I laid out in my previous messages will take care of adding Visual Changes (Editor) functionality to your Swift app - however Live Variables and Code Blocks will not.
The method laid out in @shorty 's Github page is a tested and true method in order to get Live Variables working and I recommend using it until we release a Swift compatible SDK.
I will post an update to this thread as soon as our SDK is released!
Cheers,
Paul