(点击上方公众号,可快速关注)
来源:南栀倾寒 ??
www.jianshu.com/p/c7623c31d77b
如有好文章投稿,请点击 → 这里了解详情
知识背景
What is CocoaPods(https://guides.cocoapods.org/using/getting-started.html)
What did CocoaPods do?(https://guides.cocoapods.org/using/using-cocoapods.html)
In Xcode,with references directly from the ruby source,it:
Creates or updates a workspace.
Adds your project to the workspace if needed.
Adds the CocoaPods static library project to the workspace if needed.
Adds libPods.a to: targets => build phases => link with libraries.
Adds the CocoaPods Xcode configuration file to your app’s project.
Changes your app’s target configurations to be based on CocoaPods’s.
Adds a build phase to copy resources from any pods you installed to your app bundle. i.e. a ‘Script build phase’ after all other build phases with the following:
大意是,CocoaPods是一个依赖管理工具,使用CocoaPods可以自动的去分析依赖,然后通过脚本去将第三方依赖复制编译为静态库然后链接进项目。~~~等。
有时候我们有把代码做成一个轮子给别人用情况,我们需要按照官方的教程Making CocoaPods去制作。
教程分为2类 :
发布公共Pod给所有开发者使用。
制作私有Pod。 方法较为简单。自行查阅资料即可。这里不再赘述。
参考官方的文档(文末指出),混编里面包含有2种调用情况:
Question1. Swift调用Objective-C
Question2. Objective-C调用Swift
这里我新建一个项目 命名为Mixed(Single View Application), 创建一个文件夹Classes用于存放源代码
创建一个Objective-C Class O 继承自NSObject 创建一个Swift Class S 继承自NSObject

headerConfig
有时候Xcode反应会稍微延迟一点。手动编译一下即可。做完这个配置,Swift即可访问Objective-C 源代码。
代码如图:

swiftAccessObjc