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?
根据本教程,我们应该添加use_frameworks!到Swift项目中的Podfile。但是如何在同一个项目中使用.m中的第三方代码?
One possible way is,
一种可能的方式是,
- Do NOT add
use_frameworks!
toPodfile
- Import header in
...-Bridging-Header.h
- Then, I can use third-party code in both .swift and .m file
不要添加use_frameworks!到Podfile
在...- Bridging-Header.h中导入标题
然后,我可以在.swift和.m文件中使用第三方代码
But when I try to import header in ...-Bridging-Header.h
, it just throw *.h file not found
error, how to fix this issue?
但是当我尝试在...- Bridging-Header.h中导入标题时,它只是抛出* .h文件找不到错误,如何解决这个问题?
1 个解决方案
#1
7
Past
Up to CocoaPods 1.4.x (included), it was NOT possible to use CocoaPods with Swift code without use_frameworks!
.
直到CocoaPods 1.4.x(包含),如果没有use_frameworks,就不可能将CocoaPods与Swift代码一起使用!
Present: 1.x.x and above
Nowadays, for example with CocoaPods 1.4.0 or newer, 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:
现在,例如使用CocoaPods 1.4.0或更新版本,通常使用use_frameworks!对于Swift和ObjC项目:它允许以任何方式混合使用两种语言而不会出现问题:
- 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.
您将能够在objective-c项目中使用Swift依赖项。
您将能够在Swift项目中使用objective-c依赖项。
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.
如今,CocoaPods 1.5.0支持将swift pod集成为静态库。试试吧(sudo gem install cocoapods)并享受删除use_frameworks!来自你的Podfile。
#1
7
Past
Up to CocoaPods 1.4.x (included), it was NOT possible to use CocoaPods with Swift code without use_frameworks!
.
直到CocoaPods 1.4.x(包含),如果没有use_frameworks,就不可能将CocoaPods与Swift代码一起使用!
Present: 1.x.x and above
Nowadays, for example with CocoaPods 1.4.0 or newer, 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:
现在,例如使用CocoaPods 1.4.0或更新版本,通常使用use_frameworks!对于Swift和ObjC项目:它允许以任何方式混合使用两种语言而不会出现问题:
- 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.
您将能够在objective-c项目中使用Swift依赖项。
您将能够在Swift项目中使用objective-c依赖项。
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.
如今,CocoaPods 1.5.0支持将swift pod集成为静态库。试试吧(sudo gem install cocoapods)并享受删除use_frameworks!来自你的Podfile。