swift4.0 使用错误示例及解决办法
'HGL_TitleViewStyle' initializer is inaccessible due to 'internal' protection level
1
2
3
4
5
6
7
8
9public class HGL_TitleViewStyle {
public var titleViewHeight : CGFloat = 44
public var normalColor : UIColor = UIColor.blue
public var selectColor : UIColor = UIColor.orange
public var titleSize : CGFloat = 17
public var isScrollEnable = false
public var itemMargin : CGFloat = 20
}
创建类时候没有继承类,可修改为
public class HGL_TitleViewStyle : NSObject
cannot invoke initializer for type with an argument list of type swift
由于使用了没有权限的初始化方法,导致编译器找不到该方法,将该方法暴露,使用
public
关键字即可`No such module ‘’
由于使用的是podspec模式,在写子模块时候,调用到了其他的模块时候,不能再podfile中直接使用
pod install
,而应该是在spec中添加dependency
Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swiftc failed with exit code 1
这个问题是由于在写子组件时候,物理删除了文件,但是在pod里面还有应用就报错,将pod中的引用删除即可
` Use of unresolved identifier ‘HD_TSShoppingCellModel’
在编写pod字库时候,在本地文件已经存在,但是在项目的pod里面并未引用到的,需要重新
pod install
即可引用pod字库中添加的图片资源
我使用的是
pod lib create name
的方式创建的模板工程,自带有Assets
和Classes
文件夹.
当使用这个模式来创建字库时候,在spec中引用图片资源,应该使用:1
2
3s.resource_bundles = {
'HD_AccountModule' => ['HD_AccountModule/Assets/HD_AccountModule.bundle/*']
}这样在宿主工程中引用到的就是在
source/HD_AccountModule.bundle
这个目录下的.当使用常用模式,在模板目录(HD_AccountModule/)下直接添加资源文件夹时候,引用图片资源应该使用:
1
s.resources = 'HD_AccountModule/HD_AccountModule.bundle'
pod子库中使用xib,连线后属性为nil
因为xib的实例化默认是在
mainBundle
中去寻找,当宿主工程引用子库时,子库对应的bundle
已经不是mainBundle
了,而应该是对应的.
解决办法:
在使用xib的View或者VC中重写方法,并指定bundle1
2
3
4override init(nibName nibNameOrNil: String?, bundle nibBundleOrNil: Bundle?) {
let bundle = Bundle.init(for: HD_LoginVC.self)
super.init(nibName: "HD_LoginVC", bundle: bundle)
}[!] The
HD_PassExperience_Example [Release]target overrides the
SWIFT_VERSIONbuild setting defined in
Pods/Target Support Files/Pods-HD_PassExperience_Example/Pods-HD_PassExperience_Example.release.xcconfig’. This can lead to problems with the CocoaPods installation - Use the$(inherited)
flag, or - Remove the build settings from the target.,在使用pod时候安装第三方(我安装的是WCDB.swift)时候,运行
pod install`时候,终端报错.1
2这里说的是pod Pods-HD_PassExperience_Example.debug 这个文件中的 SWIFT_VERSION 与 target中的设置有冲突,虽然能够安装,但是编译时候回报错:
在 target中setting,将SWIFT_VERSION删除(即设置成默认的)即可解决.
nav 是否隐藏问题
在自定义导航栏时候滑动滑返回时候由于导航栏是否隐藏需要使用 setNavigationBarHidden
来设置,在设置setNavigationBarHidden
之后,会关闭系统默认的右滑手势,需要手动开启,使用navigationController?.interactivePopGestureRecognizer?.delegate = self
方法将滑动权限交由控制器本身animated必须是TRUE,否则不起作用!!!
1 | override func viewDidLoad() { |
在违常理的方法调用顺序上,有可能是方法循环调用
1 | 系统的右滑手势取消后还会调用viewWillDisappear |
这个是原因是由于调用super时候调错了方法,在viewWillDisappear
中调用了super.viewWillAppear
,导致错误如下:
1 | viewWillDisappear 第一次调用,正常 |