1.新建工程 SwiftDemo

2.工程目录中新建 Lib

3.Lib
中创建.podspec
文件,首先cd到Lib目录
,并执行下面命令
pod spec create ZKKit
这里的名字不要和自己工程名字一样

4.打开ZKKit.podspec
,我使用vim
命令打开的,我只保留一些用到的
Pod::Spec.new do |spec|
spec.name = "ZKKit"
spec.version = "0.0.1"
spec.summary = "A short description of ZKKit."
spec.description = "好好学习,天天向上,Hello Word"
spec.homepage = "https://www.jianshu.com/u/621c3854d9d4"
spec.author = { "yuzhengkai" => "18311132469@163.com" }
spec.platform = :ios, "10.0"
spec.source = { :git => "", :tag => "{spec.version}" }
spec.source_files = "Classes", "Classes/**/*.{h,m}"
spec.exclude_files = "Classes/Exclude"
Lib
目录中创建Classes
目录名字和spec.source_file
中写的保持一致

如果Lib/Classes
目录下是多个不同组件则需要编写.podspec
spec.subspec "组件目录名" do |ss|
ss.source_files = "组件目录名/**/*.{swift}"
end
执行pod install

6.回到工程目录创建Podfile
touch Podfile
vim Podfile
target 'SwiftDemo' do
pod 'ZKKit', :path => './Lib'
end
:wq
保存退出
把需要用到的一些工具类放到Lib/Classes/
中
pod install --verbose --no-repo-update 或直接 pod install
成功后会生成一个SwiftDemo.xcworkspace
7.测试一下,打开SwiftDemo.xcworkspace
可以看到,然后在import
ZKKit 运行不报错说明已经成功了

8.注意
- 写本地工具类的时候一定要注意访问优先级别,有可能你可以
import
成功但是使用访问不到
open > public > internal > fileprivate > private。默认的访问等级是 internal
- 上面我说的创建
.podspec
名字不能和工程名一样,如果一样会显示NO Scheme
9.参考
https://www.jianshu.com/p/cc73bc43a187
https://www.jianshu.com/p/1e514abf286f
https://www.jianshu.com/p/9183cded6b2e
网友评论