Search code examples
xcodeswiftcocoapodsswift2chartboost

How can I use Chartboost with Cocoapods in Swift?


This is my Podfile

platform :ios, 8.0
use_frameworks!

pod "ChartboostSDK"
pod "SVProgressHUD"

SVProgressHUD is being turning into a framework, but for some reason Chartboost is not.

enter image description here

That of course makes the import for Chartboost not working in my code.


Solution

  • The library ChartboostSDK is not supported for Swift directly using CocoaPods, you need to integrate it manually in the following way:

    1.First, unzip the SDK package and drop the Chartboost Framework into your Xcode project. Be sure you've also linked these frameworks:

    • StoreKit
    • Foundation
    • CoreGraphics
    • UIKit

    2.Then you need to add a Swift bridging header allows you to communicate with your old Objective-C classes from your Swift classes.You will need one if you plan to keep portions of your codebase in Objective-C. You can create it manually like in the following way:

    1. Add a new file to Xcode (File > New > File), then select “Source” and click “Header File“.

    2. Name your file “YourProjectName-Bridging-Header.h”.

    3. Navigate to your project build settings and find the “Swift Compiler – Code Generation” section. You may find it faster to type in “Swift Compiler” into the search box to narrow down the results. Note: If you don’t have a “Swift Compiler – Code Generation” section, this means you probably don’t have any Swift classes added to your project yet. Add a Swift file, then try again.

    4. Next to “Objective-C Bridging Header” you will need to add the name/path of your header file. If your file resides in your project’s root folder simply put the name of the header file there. Examples: “ProjectName/ProjectName-Bridging-Header.h” or simply “ProjectName-Bridging-Header.h”.

    5. Open up your newly created bridging header and import your Objective-C classes using #import statements. Any class listed in this file will be able to be accessed from your swift classes.

    You bridging header must be have inside the following lines:

    #import <UIKit/UIKit.h>
    #import <Chartboost/Chartboost.h>
    #import <Chartboost/CBNewsfeed.h>
    #import <CommonCrypto/CommonDigest.h>
    #import <AdSupport/AdSupport.h>
    

    You can read more about the next steps using Charboost in his iOS Integration help manual.

    I hope this help you.