本人小白,欢迎各位大佬补充指点
swift3.0到swift4.0变化总结:(工作中一直更新)
- private修饰在分类中使用功能恢复
- 设备相机枚举,类更细分
AVMetadataObjectTypeCode128Code -> AVMetadataObject.ObjectType.code128
AVCaptureSessionPreset1920x1080 -> AVCaptureSession.Preset.hd1920x1080
AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeVideo) -> AVCaptureDevice.default(for: AVMediaType.video) - 按command左键点击代码会有弹窗选择进入类详情或帮助,右键直接进详情
-
#
selector方法需要@objc修饰 - 注意:Xcode一直会有一个警告:The use of Swift 3 @objc inference in Swift 4 mode is deprecated警告
解决方法:build setting swift3 @objc inference 设置为off

- 提示信息可以复制
- MPI -> Double.pi(π的写法)
- 字体富文本属性属性(这个改的还是不错的)
NSFontAttributeName->NSAttributedStringKey.font
NSParagraphStyleAttributeName->NSAttributedStringKey.paragraphStyle
NSForegroundColorAttributeName ->NSAttributedStringKey.foregroundColor - 所有通知名改为
NSNotification.Name.XXX.rawValue - 在swift 4.0中用系统方法setValuesForKeys()赋值问题
在swift 4.0中使用系统方法setValuesForKeys()进行赋值,明明有这个属性,但它还是走
override func setValue(_ value: Any?, forUndefinedKey key: String)这个未定义的方法
解决办法:
@objc var content = ""
swift 4.0 版本要在所有模型属性前面加@objc - 错误:Initializer for conditional binding must have Optional type, not“()”
移除guard else{}即可,你把不是可选类型的用guard判断了 - 二维码扫描代理方法替换:(这TMD就不知道苹果咋想的,毫无提示的修改了API)AVCaptureMetadataOutputObjectsDelegate
替换前:
func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputMetadataObjects metadataObjects: [Any]!, from connection: AVCaptureConnection!)
替换后:
func metadataOutput(_ output: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection)
这个连个提示都没有
网友评论