cocoapods建swift版本的私有库时注意的地方

Swift私有库步骤和OC私有库一样, pod lib create xxxx初始化时允许 include a demo application建立Example工程。我这边podspec文件里依赖了 SnapKit ,并 pod install

s.dependency 'SnapKit', '~> 4.0.0'

然而 pod lib lint 出现podspec验证不通过。这里的23个error都是跟 SnapKit 有关。

- WARN  | [DCCJAlertLoadingLib/DCCJAlert,DCCJAlertLoadingLib/DCCJLoading] swift: The validator used Swift 3.2 by default  because no Swift version was specified. To specify a Swift version during validation, add the `swift_version` attribute in your podspec. Note that usage of the `--swift-version` parameter or a `.swift-version` file is now deprecated.

- ERROR | [DCCJAlertLoadingLib/DCCJAlert,DCCJAlertLoadingLib/DCCJLoading] xcodebuild:  SnapKit/Source/ConstraintViewDSL.swift:86:63: error: argument labels '(rawValue:)' do not match any available overloads
- NOTE  | [DCCJAlertLoadingLib/DCCJAlert,DCCJAlertLoadingLib/DCCJLoading] xcodebuild:  SnapKit/Source/ConstraintViewDSL.swift:
86:63: note: overloads for 'LayoutPriority' exist with these partially matching parameter lists: (_bits: FPIEEE32), (from: Decoder), (S), (bitPattern: UInt32), (floatLiteral: Float), (_builtinIntegerLiteral: Int2048), (integerLiteral: Int64),(_builtinFloatLiteral: FPIEEE80), (exactly: T), (UInt8), (exactly: UInt8), (Int8), (exactly: Int8), (UInt16), (exactly: UInt16), (Int16), (exactly: Int16), (UInt32), (exactly: UInt32), (Int32), (exactly: Int32), (UInt64), (exactly: UInt64),(Int64), (exactly: Int64), (UInt), (exactly: UInt), (Int), (exactly: Int), (Float), (exactly: Float), (Double), (exactly: Double), (Float80), (exactly: Float80), (CGFloat), (NSNumber), (truncating: NSNumber), (exactly: NSNumber)

[!] DCCJAlertLoadingLib did not pass validation, due to 23 errors and 1 warning.
You can use the `--no-clean` option to inspect any issue.
  • error和note都是和依赖库有关,不能直接修改三方库内容。大意是集成的SnapKit的swift版本不匹配,同时warning里面也可以看到,需要使用 .swift-version 文件。这个文件默认是没有的,需要手动添加。

1. cd进入Example的上层文件目录

2.创建 .swift-version 文件

touch .swift-version

3.设置swift版本号,根据当前xcode能支持的最高版本来

echo "4.1" > .swift-version

4.查看swift版本号

cat .swift-version
  • 这个时候再pod lib lint,依旧报了error,但是跟之前的error不一样

- ERROR | [DCCJAlertLoadingLib/DCCJAlert] xcodebuild:  /Users/tangyuan/Desktop/617/work/项目/永达/私有库/
DCCJAlertLoadingLib/DCCJAlertLoadingLib/Classes/DCCJAlert/CustomeAlertViewController.swift:337:13: error: value of 
type 'UIButton' has no member 'snp'

[!] DCCJAlertLoadingLib did not pass validation, due to 23 errors and 1 warning.
You can use the `--no-clean` option to inspect any issue.

这里报错就是SnapKit没有正确引入,只要cd Example进入工程,pod install后退到上层目录pod lib lint --allow-warnings即可。

总结: 建立swift版本私有库时,一定不要忘记添加.swift-version文件。如有表述不当的,欢迎指正。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。