How to integrate Cocoapods with a Swift project?

前端 未结 6 788
感情败类
感情败类 2020-12-04 06:41

As Apple introduced Swift, their new programming language, I wonder how you can integrate it with existing Objective-C libraries that are available via CocoaPods?

6条回答
  •  不知归路
    2020-12-04 07:22

    UPDATE: CocoaPods 0.36 stable version has been released. It officially supports Swift.


    CocoaPods now supports Swift in their latest 0.36 release. It's still in beta but it works.

    First you need to install the CocoaPods beta (currently beta 2) by running this in your Terminal.

    sudo gem install cocoapods --pre
    

    That's pretty much it. You can add Swift libraries like you would do normally.

    But there's a catch if you want to add a library written in Objective-C to a Swift project via CocoaPods. You need to add the line use_frameworks! to your Podfile. Here's an example.

    use_frameworks!
    platform :ios, '8.0'
    
    pod 'MagicalRecord'
    

    I wrote a blog post regarding this as well.

提交回复
热议问题