Closed samirahmed closed 7 years ago
+1
hey @samirahmed, @Pasta - you're absolutely right that you cannot define MPTweakValue in Swift. MPTweaks are constructed with a Preprocessor Macro, and we're working to move this to a Swift function so everything is compatible and usable in a Swift project. this should be coming in a future release - for now, Tweaks need to be defined in an objc file just as you've found. sorry to be the bringer of bad news here!
@arittr Would also like to use tweaks in a swift project. Don't quite understand the current workaround. Can you elaborate? Thanks!
@bradfol we're working on moving our tweaks code to a Swift function - for now, you can only use MPTweak/TweakValue in an Objective-C class. you can have Obj-C and Swift classes side by side in a project, but Tweaks cannot be used in Swift classes right now. i'll close/update this issue when the new release is done. thanks!
@arittr Thanks for clarifying. Hope to see some updates for Swift soon!
+1
+1
Managed to get this to work. The trick is to use the MPTweakStore directly. Here's the gist :
https://gist.github.com/ohad7/8ce12a432773fe3b1bf3
Hope this helps.
@ohad7 this is super cool, thanks so much for sharing! i'm going to test this out today.
Thanks! I got to test it a bit more and make a few changes, please take a look. I'm now relying on Mixpanel to refresh the experiments every time the app goes to background (instead of doing it myself every 30 mintues), and I'm persisting the tweaks to the disk since Mixpanel won't give you the same experiment twice. Will update in case I find bugs etc.
@ohad7 sounds great - I'll take another look today. FWIW variants/experiments will persist in /decide - so in effect Mixpanel will serve the experiment every time the app is opened (or /decide is manually polled). that being said caching is a great idea and something our library does anyway.
you might want to consider a PRQ / forking the lib - I know several people who are interested in something like this. thanks again for being awesome!
What's the status on this? Half a year after and it's still impossible to use Mixpanels Tweaks in a Swift app, unless you include @ohad7's file?!
+1
+1
its been 8 months and mixpanel hasn't answered ... anybody still waiting on a fix should just bridge the gap with the wrapped call to an objc method that just makes this one call
Is it just me or is it not totally bonkers that this doesn't work out of the box?
We're planning on pushing a release this week that will resolve this issue. Thanks for your patience.
@samgreen How's the release coming along?
It seems that this has not been fixed in 2.8.3 as I am using that version and I still get an error with Swift.
@samgreen Can we get an update from MixPanel?
@holgersindbaek Absolutely, sorry for the delay on this. It's not such a simple change as was linked in the gist above. We released v2.9.0 on Friday and this has laid the groundwork for future Swift support.
Unfortunately the mechanism by which we read all of the tweaks from the binary (seen here: https://github.com/mixpanel/mixpanel-iphone/blob/bdd0f5a7f33ea0bfc4193f84ae2ed80258215bab/Mixpanel/MPTweakInline.m#L127), is not compatible with the way Swift only projects are compiled. It appears to us that the Swift compiler is not only mangling symbols and names, but rearranging where things are placed in the Mach-O header. The way we accomplish the magic for tweaks relies heavily on this concept.
We are reviewing possible solutions at this time, but we would love any input from our community on this one.
That said, if you use the gist above, the tweaks will function correctly, but you will only be able to see them on the website when you have that specific view / view controller loaded. This is a non-optimal solution, and definitely not one that we wanted to ship to our users.
Hopefully #364 will resolve this issue. Thanks for your patience everyone.
"This is a non-optimal solution, and definitely not one that we wanted to ship to our users."
Any new updates Sam? Thanks.
Hi @vandutran, thanks for checking in. At this point the only problem we face is the lack of the __attribute
LLVM keyword in swift. We use this keyword to locate the tweaks by name in the application binary. I am currently investigating using global static variables so we would be able to locate those instead, but we are running in to issues with Swift's name mangling.
We care deeply about this issue and are hard at work restoring this magical feature for Swift. Thanks so much for your continued patience.
So the problem is that you're using some dark magic to extract the list of all tweak names used in MPTweakLabel() calls, and you can't do that for Swift because compiled Swift code looks different than compiled ObjC code, did I get that right?
I've added the call in an ObjC file as a workaround, but the tweaks still don't appear in the A/B builder on the site, am I doing something wrong? Or is it that if the app includes any Swift at all, the tweaks don't work, even if they're in an ObjC file?
I've tried the same thing, @mackuba , and likewise the tweaks aren't appearing in A/B builder. I've emailed them, so I will let you know what they say.
just wanted to get a 2-week check in for any updates on this issue, @cph2117 have you heard back?
cc @samgreen
Thanks!
I asked and got feedback.
Tweaks are not compatible with Swift yet.
This is a known issue: https://github.com/mixpanel/mixpanel-iphone/issues/229
I would recommend following that issue on Github so that you automatically get updates.
Sorry I don't have better news at the moment, but we are working on this, I'm just not certain when it will be available.
hmm....
+1
@SRandazzo sorry for the huge delay, I didn't see your question.
We ended up scrapping this and using Optimizely. So now we have Optimizely for AB testing and Mixpanel for event tracking.
Any progress on this yet?
Hello guys, any news ??
@samgreen Still no timeline for this?
??
I just want to point out that it is definitely possible to use MPTweakValue in a Swift project, you would just have to use a bridging header and write your tweaks in Objective-C. You can read more about this here: https://mixpanel.com/help/reference/ios#tweaks under the "Swift" section.
@yarneo whilst I believe most people here are aware of that solution (see thread), I think the point of this issue is to request a native swift solution rather than having to use objective C and a bridging header as a clunky and half-baked workaround.
@chrisvxd Thanks for the comment. The reason I am pointing it out, is that some people are not aware it is possible and I wanted to clarify. Rest assured that once we have a solution we will update this thread.
Losing hope :(
Still a deal breaker for us...
found this https://mixpanel.com/help/reference/swift
As @xManson mentioned, we now have a Swift library that also supports A/B testing and tweaks. The mechanism is different but you can see how to initialize and use the tweaks here: https://mixpanel.com/help/reference/swift#tweaks
Great news!
Closing this issue. If someone wishes to use Tweaks in Swift, then please use our Swift library!
The inline helper syntax conflicts with the MPTweakValue type constructor syntax ... As far as I can tell this cannot be called in swift - you have to create a objc file just to call this helper
Would be nice if you gave it a different name or named the typed differently ... or if there is a way to call it from swift please let me know :smile: