- 先创建一个本地库的项目目录(如 MyTool),并进入该目录:
cd 文件的路径
mkdir MyTool && cd MyTool
- 生成 podspec 模板
pod spec create MyTool
- 配置 podspec 文件
Pod::Spec.new do |s|
s.name = "MyTool"
s.version = "1.0.0"
s.summary = "本地工具库"
# 用占位URL避免警告
s.homepage = "https://github.com/yourname/MyTool"
# 关联本地LICENSE文件
s.license = { :type => "MIT", :file => "LICENSE" }
s.author = { "Your Name" => "your@email.com" }
# Git仓库配置(确保路径正确)
s.source = {
:git => "file:///Users/junqi/Desktop/navigationTest/MyTool",
:tag => s.version.to_s
}
# 关键:根据find命令的输出修改路径
# 例如find命令找到./Classes/*.h和./Utils.swift,则配置:
s.source_files = "Tool/**/*.{h,m}", "*.swift"
s.platform = :ios, "12.0"
end
- 验证 podspec 有效性
pod spec lint MyTool.podspec
若输出 MyTool.podspec passed validation.,说明配置正确;若有错误,根据提示修改 podspec 文件后重新验证。
- 在项目中引入本地库
target "YourProject" do
pod 'MyTool', :path => '../MyTool' # 替换为本地库的实际路径
end
注意: 一定 要初始换你的git仓库
cd /Users/junqi/路径/到/MyTool
git init
git add .
git commit -m "Initial commit"
git tag 1.0.0 # 必须创建与s.version一致的tag
所有工作做完就可以 在项目工程中pod install 你的项目在cocoapods里面调用你的类文件