How to integrate Chartboost IOS SDK with Swift

I am trying to integrate the Chartboost IOS SDK with Swift. I have followed all the instructions on the Chartboost IOS Integration page https://answers.chartboost.com/hc/en-us/articles/201220095-iOS-Integration and have created a bridging header to use the framework in my swift project.

BridgingHeader.h

  • How can I change modifier keys in “System Preferences > Keyboard > Modifier Keys…”
  • UICollectionView snap onto cell when scrolling horizontally
  • What exactly does delegate do in xcode ios project?
  • clear color background nav bar, but still float above all the contents
  • Dynamic cell width of UICollectionView depending on label width
  • How to search the iphone address book for a specific phone number?
  • #import <Chartboost/Chartboost.h>
    #import <Chartboost/CBNewsfeed.h>
    #import <CommonCrypto/CommonDigest.h>
    #import <AdSupport/AdSupport.h>
    

    My BridgingHeader.h file is loacated in my project root directory http://img.ioscake.com/objective-c/DcTcixo.png and I have followed the necessary steps to add the BridgingHeader.h to my Build Settings http://img.ioscake.com/objective-c/jvtzs7a.png but when I run the project I get 52 errors like -> http://img.ioscake.com/objective-c/WCvyooz.png. Why am I getting these errors and how do I get rid of them?

    4 Solutions Collect From Internet About “How to integrate Chartboost IOS SDK with Swift”

    It looks like the headers require UIKit and Foundation. Add this line at the top of your bridging header.

    #import <UIKit/UIKit.h>
    

    Also, have you made sure your bridging header is in the project’s root in the file system? The hierarchy of Xcode’s Project Navigator isn’t necessarily the same as the file system.

    It’s looking for the header in /Users/andrew/Documents/dev/ios/Protect Paigridge/ Open finder and make sure that the header is in that directory. Xcode may have created it a level deeper where the rest of your code files are. If that’s the case, you can edit entry in Build Settings or move the file.

    Adding onto the top answer said above try adding both

    #import <Foundation/Foundation.h>
    #import <UIKit/UIKit.h>
    #import <Chartboost/Chartboost.h>
    

    to your BridgingHeader.h File

    and make sure they are both above the

    #import <Chartboost/Chartboost.h>
    

    as shown above

    Swift Chartboost Code, Add it in AppDelegate Class :

    func applicationDidBecomeActive(application: UIApplication) 
    {        
        let kChartboostAppID = "5472ef8f04b01601a1a5814c";
        let kChartboostAppSignature = "5b6222426e68cda48669a1d4d8246d4c3d20db9c";
    
        Chartboost.startWithAppId(kChartboostAppID, appSignature: kChartboostAppSignature, delegate: self);
        Chartboost.cacheMoreApps(CBLocationHomeScreen)
    }
    
    class func showChartboostAds()
    {
         Chartboost.showInterstitial(CBLocationHomeScreen);
    }
    
    func didFailToLoadInterstitial(location :String!, withError error: CBLoadError)
    {
    
    }
    
    func didDismissInterstitial(location :String! )
    {
            if(location == CBLocationHomeScreen)
            {
                Chartboost.cacheInterstitial(CBLocationMainMenu)
            }
            else if(location == CBLocationMainMenu)
            {
                Chartboost.cacheInterstitial(CBLocationGameOver)
            }
            else if(location == CBLocationGameOver)
            {
                Chartboost.cacheInterstitial(CBLocationLevelComplete)
            }
            else if(location == CBLocationLevelComplete)
            {
                Chartboost.cacheInterstitial(CBLocationHomeScreen)
            }
     }
    

    Calling Syntax:

       AppDelegate.showChartboostAds()
    

    This issue is how to import.

    You can make objC code and bridge.h, to shows in your code

    [Chartboost showInterstitial:CBLocationHomeScreen];

    For swift

    Chartboost.showInterstitial(CBLocationHomeScreen)

    i wish that help you