Swift3.0 - 遇到的坑

Swift3.0 - 真的很简单
Swift3.0 - 数据类型
Swift3.0 - Array
Swift3.0 - 字典
Swift3.0 - 可选值
Swift3.0 - 集合
Swift3.0 - 流控制
Swift3.0 - 对象和类
Swift3.0 - 属性
Swift3.0 - 函数和闭包
Swift3.0 - 初始化和释放
Swift3.0 - 协议protocol
Swift3.0 - 类和结构体的区别
Swift3.0 - 枚举
Swift3.0 - 扩展
Swift3.0 - 下标
Swift3.0 - 泛型
Swift3.0 - 异常错误
Swift3.0 - 断言
Swift3.0 - 自动引用计数(strong,weak,unowned)
Swift3.0 - 检测API
Swift3.0 - 对象的标识
Swift3.0 - 注释
Swift3.0 - 元类型
Swift3.0 - 空间命名
Swift3.0 - 对象判等
Swift3.0 - 探究Self的用途
Swift3.0 - 类簇
Swift3.0 - 动态调用对象(实例)方法
Swift3.0 - 文本输出
Swift3.0 - 黑魔法swizzle
Swift3.0 - 镜像
Swift3.0 - 镜像
Swift3.0 - 遇到的坑

  • 在扩展中写静态方法

      extension UIButton{
          static var count:Int = 0
      }
    

报错提示:

a declaration cannot be both 'final' and 'dynamic'

原因分析:

当前类是继承于NSObject的,swift为了swift和Obj-C的兼容为静态变量生成一个动态访问器,如果你的工程是只支持swift的,你可以使用@nonobjc属性避免这个问题

  • 麦克风权限
    报错:

app has crashed because it attempted to access privacy-sensitive data without a usage description. The app's Info.plist must contain an NSMicrophoneUsageDescription key with a string value explaining to the user how the app uses this data.

解决:

在info 添加键值对 Privacy - Microphone Usage Description

Swift3.0 - 遇到的坑_第1张图片
让学习成为一种习惯
  • 照相权限

解决 :

在info添加键值:NSCameraUsageDescription

Swift3.0 - 遇到的坑_第2张图片
让学习成为一种习惯
  • 给 UIViewController 的子类增加一个新的初始化方法
      init(deviceIP:String,port:UInt16){
        super.init(nibName: nil, bundle: nil)
     }

不是是下面这种

    init(deviceIP:String,port:UInt16){
        super.init()
     }

原因:

只能调用父类的指定初始化方法

  • 使用UDP 和android 进行通讯的时候,安卓广播数据,iOS接受不到数据

将主机地址改为 224.0.0.1 就乐了!

  • NSCache 初始化时报错,提示不能推断
var cache = NSCache()

修改:

 var cache =  NSCache()
  • clang: error: linker command failed with exit code 1 (use -v to see invocation)

可能导致错误因素

由于使用了第三方框架,可能有冲突的扩展方法名

解决办法


Swift3.0 - 遇到的坑_第3张图片
5EB64D2F-9685-437A-91F7-90017DC77689.png
  • iOS 10 之后权限设置

麦克风权限:Privacy - Microphone Usage Description 是否允许此App使用你的麦克风?
相机权限: Privacy - Camera Usage Description 是否允许此App使用你的相机?
相册权限: Privacy - Photo Library Usage Description 是否允许此App访问你的媒体资料库?
通讯录权限: Privacy - Contacts Usage Description 是否允许此App访问你的通讯录?
蓝牙权限:Privacy - Bluetooth Peripheral Usage Description 是否许允此App使用蓝牙?
语音转文字权限:Privacy - Speech Recognition Usage Description 是否允许此App使用语音识别?
日历权限:Privacy - Calendars Usage Description
定位权限:Privacy - Location When In Use Usage Description
定位权限: Privacy - Location Always Usage Description
位置权限:Privacy - Location Usage Description
媒体库权限:Privacy - Media Library Usage Description
健康分享权限:Privacy - Health Share Usage Description
健康更新权限:Privacy - Health Update Usage Description
运动使用权限:Privacy - Motion Usage Description
音乐权限:Privacy - Music Usage Description
提醒使用权限:Privacy - Reminders Usage Description
Siri使用权限:Privacy - Siri Usage Description
电视供应商使用权限:Privacy - TV Provider Usage Description
视频用户账号使用权限:Privacy - Video Subscriber Account Usage Description

你可能感兴趣的:(Swift3.0 - 遇到的坑)