Search code examples
swiftios8xcode6mixpanel

Mixpanel does not work with swift


Cocoapods is not ready for Swift yet. When I implemented Mixpanel into my iOS project that uses Swift, I got several errors.

enter image description here

How to fix this issue and make mixpanel to work?


Solution

  • Add this line of code to every file that is giving an error

    #import <UIKit/UIKit.h>
    

    Also need to add these in your linked frameworks and libraries:

    libicucore.dylib  
    CFNetwork.framework  
    Security.framework
    

    Then add this to your Bridging-Header.h file:

    #import "Mixpanel.h"
    

    Then add this piece of code in your appdelegate:

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
        //other stuff here
        Mixpanel.sharedInstanceWithToken("yourtokennumbergoeshere")
        var mixPanel = Mixpanel.sharedInstance()
    
        mixPanel.track("Finished Launching", properties: ["name1":"property1","name2":"property2"])
    
        return true
    }