大名信息港,海鹰战斗机,孕妇能吃杨梅吗
目前ios组件化常用的解决方案是pod+路由+持续集成,通常架构设计完成后第一步就是将原来工程里的模块按照架构图分解为一个个独立的pod工程(组件),今天我们就来看看如何创建一个pod私有库。
假设我们需要创建的库名为testlib,下面我们使用pod官方提供的创建模板:
pod lib create testlib
import foundation public class classa { //这是public类,可被外部工程访问 public let name = "classa" let age = 18 } class classb { //不是public类,不能被外部工程访问 let name = "classb" }
pod install
public
修饰的属性到这里使用pod新建一个私有库就完成了。
新建完成后,我们还需要验证,需要修改配置文件,通过下面的截图路径找到新建的私有库的配置文件:
或者在xcode里的:
文件内容:
# # be sure to run `pod lib lint testlib.podspec' to ensure this is a # valid spec before submitting. # # any lines starting with a # are optional, but their use is encouraged # to learn more about a podspec see https://guides.cocoapods.org/syntax/podspec.html # pod::spec.new do |s| # 名称、版本号、概述 s.name = 'testlib' s.version = '0.1.0' s.summary = 'a short description of testlib.' # this description is used to generate tags and improve search results. # * think: what does it do? why did you write it? what is the focus? # * try to keep it short, snappy and to the point. # * write the description between the desc delimiters below. # * finally, don't worry about the indent, cocoapods strips it! # 详细描述 s.description = <<-desc todo: add long description of the pod here. desc # 主页、截图、license证书、作者信息、源代码地址、社交地址 s.homepage = 'https://github.com/xxx/testlib' # s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2' s.license = { :type => 'mit', :file => 'license' } s.author = { 'xxx' => 'xxx@xxx.com' } s.source = { :git => 'https://github.com/xxx/testlib.git', :tag => s.version.to_s } # s.social_media_url = 'https://twitter.com/<twitter_username>' # ios版本 s.ios.deployment_target = '8.0' # 源码所在路径 s.source_files = 'testlib/classes/**/*' # 资源文件所在地址 # s.resource_bundles = { # 'testlib' => ['testlib/assets/*.png'] # } # 对外公开的h文件地址,swift一般用不到 # s.public_header_files = 'pod/classes/**/*.h' # 包含的系统framework # s.frameworks = 'uikit', 'mapkit' # 包含的第三方pod # s.dependency 'afnetworking', '~> 2.3' end
更详细的介绍可以访问官网
配置好以后我们需要做一次验证,在工程目录下使用命令
pod lib lint
could not find a `ios` simulator (valid values: ). ensure that xcode -> window -> devices has at least one `ios` simulator listed or otherwise add one.
1.sudo gem uninstall fourflusher 2.sudo gem install fourflusher
必要的话还需要更新pod
sudo gem update cocoapods
[!] testlib did not pass validation, due to 3 warnings (but you can use `--allow-warnings` to ignore them).
--allow-warnings
pod lib lint --allow-warnings
如果验证通过,会看到testlib passed validation.
,到这一步既完成验证
通过pod官方模板做出来的工程ios版本为8.0,swift版本为4.0,我们有时需要根据需要修改版本号,需要在spec文件中添加:
# ios版本 s.ios.deployment_target = '9.0' # swift版本 s.swift_versions = '5.0'
然后执行pod install
更新工程即可
现在私有git服务器创建testlib项目,然后回到工程目录,使用git初始化命令:
git init git remote add origin http://私有仓库地址/testlib.git git add . git commit -m 'init' git push -u origin master
然后修改spec文件内容
# 主页、截图、license证书、作者信息、源代码地址、社交地址 s.homepage = 'http://私有库地址/testlib.git' # s.screenshots = 'www.example.com/screenshots_1', 'www.example.com/screenshots_2' s.license = { :type => 'mit', :file => 'license' } s.author = { 'xxx' => 'xxx@xxx.com' } s.source = { :git => 'http://私有库地址/testlib.git', :tag => s.version.to_s }
如果需要对外发布版本时需打tag,然后创建同名branch
git tag -a 0.1.0 -m '0.1.0'
git branch 0.1.0
有时我们不希望提供源代码,只提供framework给外部调用,可以使用package
,首先安装pod插件:
sudo gem install cocoapods-packager
package参数:
参数名 | 注释 |
---|---|
--force | 覆盖之前的文件 |
--no-mangle | 1.表示不使用name mangling技术,pod package默认是使用这个技术的。我们能在用pod package生成二进制库的时候会看到终端有输出mangling symbols和building mangled framework。表示使用了这个技术。2.如果你的pod库没有其他依赖的话,那么不使用这个命令也不会报错。但是如果有其他依赖,不使用--no-mangle这个命令的话,那么你在工程里使用生成的二进制库的时候就会报错:undefined symbols for architecture x86_64。 |
--embedded | 生成静态framework |
--library | 生成静态.a |
--dynamic | 生成动态framework |
--bundle-identifier | 动态framework需要的签名 |
--exclude-deps | 不包含依赖的符号表,生成动态库的时候不能包含这个命令,动态库一定需要包含依赖的符号表 |
--configuration | 表示生成的库是debug还是release,默认是release。--configuration=debug |
--subspecs | 如果你的pod库有subspec,那么加上这个命名表示只给某个或几个subspec生成二进制库,--subspecs=subspec1,subspec2。生成的库的名字就是你podspec的名字,如果你想生成的库的名字跟subspec的名字一样,那么就需要修改podspec的名字。 这个脚本就是批量生成subspec的二进制库,每一个subspec的库名就是podspecname+subspecname。 |
--spec-sources=private,https://github.com/cocoapods/specs.git | 一些依赖的source,如果你有依赖是来自于私有库的,那就需要加上那个私有库的source,默认是cocoapods的specs仓库。--spec-sources=private,https://github.com/cocoapods/specs.git。 |
可以使用下面的命令打包:
pod package testlib.podspec --force
如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复
iOS 使用UITextField自定义搜索框 实现用户输入完之后“实时搜索”功能
网友评论