Using cocoapods without use_frameworks! in Swift
Asked Answered
C

1

6

According to this tutorial, we should add use_frameworks! to Podfile in Swift project. But how to use third-party code in .m in the same project?

One possible way is,

  • Do NOT add use_frameworks! to Podfile
  • Import header in ...-Bridging-Header.h
  • Then, I can use third-party code in both .swift and .m file

But when I try to import header in ...-Bridging-Header.h, it just throw *.h file not found error, how to fix this issue?

Cream answered 3/11, 2015 at 6:41 Comment(0)
T
11

Past

Up to CocoaPods 1.4.x (included), it was NOT possible to use CocoaPods with Swift code without use_frameworks!.

Present: 1.x.x and above

Nowadays, with CocoaPods 1.x.x (I verified it with 1.4.0), it's common to use use_frameworks! for both Swift and ObjC projects: it allows for a mix of the two languages in any way you want without issues:

  • You'll be able to use a Swift dependency in an Objective-C project.
  • You'll be able to use an Objective-C dependency in a Swift project.

Present: 1.5.x and above

Nowadays, CocoaPods 1.5.0 supports integrating swift pods as static libraries. Try it (sudo gem install cocoapods) and enjoy removing use_frameworks! from your Podfile.


Note that for iOS:

  • Apple requires Xcode 10.1 minimum, which is only well supported starting CocoaPods 1.6.0, so don't bother using older versions of CocoaPods.
  • Apple will require Xcode 11 minimum in April 2020, for which I would only use CocoaPods 1.7.5 or newer, together with xcodeproj 1.13.0 or newer.
Tenner answered 18/3, 2018 at 11:12 Comment(1)
For Xcode 11 compatibility, I would only use CocoaPods 1.7.5 or newer.Papiamento

© 2022 - 2024 — McMap. All rights reserved.