Rich-text Reply

Optimizely iOS SDK and Swift

sampathd 09-16-14

Optimizely iOS SDK and Swift

[ Edited ]

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

Level 2

pkasso 09-16-14
 

Re: Optimizely iOS SDL and Swift

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

 



Optimizely
pkasso 09-17-14
 

Re: Optimizely iOS SDL and Swift

[ Edited ]

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 Smiley Happy

Paul

Optimizely
sampathd 09-27-14
 

Re: Optimizely iOS SDL and Swift

Thanks for the answers. Got it to work.

Level 2
sampathd 10-01-14
 

Re: Optimizely iOS SDL and Swift

Hi Paul,

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
Level 2
shorty 10-06-14
 

Re: Optimizely iOS SDL and Swift

Unfortunaltey I always get the following error with my out-of-the-box Swift project:
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.
Level 2
pkasso 10-06-14
 

Re: Optimizely iOS SDL and Swift

Hi Shorty,

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 Smiley Happy
Optimizely
shorty 10-06-14
 

Re: Optimizely iOS SDL and Swift

Hi PKasso,
well, I did that, but the build script keeps adding them again.
Level 2
pkasso 10-06-14
 

Re: Optimizely iOS SDL and Swift

Hi Shorty -

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.
Optimizely
sampathd 10-06-14
 

Re: Optimizely iOS SDL and Swift

Hi,


What about my question in this thread? Am I being ignored?

Level 2
sampathd 10-06-14
 

Re: Optimizely iOS SDL and Swift

Hi,

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
Level 2
pkasso 10-06-14
 

Re: Optimizely iOS SDL and Swift

Hi Sam -

You have definitely not been ignored! I will be sending you an email shortly with more details on Swift compatibility.

Cheers,
Paul
Optimizely
shorty 10-07-14
 

Re: Optimizely iOS SDL and Swift

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. 

Level 2
pkasso 10-08-14
 

Re: Optimizely iOS SDL and Swift

[ Edited ]

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 Smiley Happy

 

@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

 

Optimizely