美文网首页
Swift那些事儿

Swift那些事儿

作者: 凉白开0072 | 来源:发表于2017-10-16 17:09 被阅读116次

本人小白,欢迎各位大佬补充指点
swift3.0到swift4.0变化总结:(工作中一直更新)

  1. private修饰在分类中使用功能恢复
  2. 设备相机枚举,类更细分
    AVMetadataObjectTypeCode128Code -> AVMetadataObject.ObjectType.code128
    AVCaptureSessionPreset1920x1080 -> AVCaptureSession.Preset.hd1920x1080
    AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeVideo) -> AVCaptureDevice.default(for: AVMediaType.video)
  3. 按command左键点击代码会有弹窗选择进入类详情或帮助,右键直接进详情
  4. #selector方法需要@objc修饰
  5. 注意:Xcode一直会有一个警告:The use of Swift 3 @objc inference in Swift 4 mode is deprecated警告
    解决方法:build setting swift3 @objc inference 设置为off
123.png
  1. 提示信息可以复制
  2. MPI -> Double.pi(π的写法)
  3. 字体富文本属性属性(这个改的还是不错的)
    NSFontAttributeName->NSAttributedStringKey.font
    NSParagraphStyleAttributeName->NSAttributedStringKey.paragraphStyle
    NSForegroundColorAttributeName ->NSAttributedStringKey.foregroundColor
  4. 所有通知名改为
    NSNotification.Name.XXX.rawValue
  5. 在swift 4.0中用系统方法setValuesForKeys()赋值问题
    在swift 4.0中使用系统方法setValuesForKeys()进行赋值,明明有这个属性,但它还是走
    override func setValue(_ value: Any?, forUndefinedKey key: String)这个未定义的方法
    解决办法:
    @objc var content = ""
    swift 4.0 版本要在所有模型属性前面加@objc
  6. 错误:Initializer for conditional binding must have Optional type, not“()”
    移除guard else{}即可,你把不是可选类型的用guard判断了
  7. 二维码扫描代理方法替换:(这TMD就不知道苹果咋想的,毫无提示的修改了API)AVCaptureMetadataOutputObjectsDelegate
    替换前:
    func captureOutput(_ captureOutput: AVCaptureOutput!, didOutputMetadataObjects metadataObjects: [Any]!, from connection: AVCaptureConnection!)
    替换后:
    func metadataOutput(_ output: AVCaptureMetadataOutput, didOutput metadataObjects: [AVMetadataObject], from connection: AVCaptureConnection)
    这个连个提示都没有

相关文章

网友评论

      本文标题:Swift那些事儿

      本文链接:https://www.haomeiwen.com/subject/ufqluxtx.html