- 带参数的函数,都加入了 _ 省略参数名的标记
func log(_ info:String) {} // 3.0
func log(info:String) {} //2.3
类&类成员说明public 关键字变成open
函数说明privite 关键字变成 fileprivate
枚举定义的case 语法字段命名不支持大写开头,统一采用小写
public enum BMPlayerTopBarShowCase: Int {
case always = 0 /// 始终显示
case horizantalOnly = 1 /// 只在横屏界面显示
case none = 2 /// 不显示
}//3.0
public enum BMPlayerTopBarShowCase: Int {
case Always = 0 /// 始终显示
case HorizantalOnly = 1 /// 只在横屏界面显示
case None = 2 /// 不显示
}//2.3
5.String 类 & UIColor 类 & Data类& TableView代理类 & Array 类 等 API的修改 ;添加了URL 的纯swift 的类实现
6.sizeof() 被MemoryLayout<T>.size 替代
tmp = subWord(rotateLeft(UInt32.withBytes(tmp), 8).bytes(MemoryLayout<UInt32>.size))//3.0
tmp = subWord(rotateLeft(UInt32.withBytes(tmp), 8).bytes(sizeof(UInt32)))//2.3
7.操作符<< 、 >> 等 declared in protocol must be static
private protocol BitshiftOperationsType {
static func << (lhs: Self, rhs: Self) -> Self //3.0
func >> (lhs: Self, rhs: Self) -> Self //2.3
}
8.DisPatch 改动较多
DispatchQueue.global(priority: 0).async {} // 2.3
public enum GlobalQueuePriority {
@available(OSX, deprecated: 10.10, message: "Use qos attributes instead")
@available(iOS, deprecated: 8.0, message: "Use qos attributes instead")
@available(tvOS, deprecated, message: "Use qos attributes instead")
}
9.dispatch_once 被自动替换:这里有坑
private lazy var __once: () = {
let pagesContainerHeight = SwiftPages.frame.size.height - SwiftPages.yOrigin - SwiftPages().distanceToBottom
}() // 3.0 错误的转换,看不懂的语法
override public func drawRect(rect: CGRect) {
dispatch_once(&token) {
let pagesContainerHeight = self.frame.height - self.yOrigin - self.distanceToBottom
}
}//2.3
**这里有点坑啊 ,转换的代码完全看不懂,self 被类本身替换,drawRect方法也被替换掉了,然后编译不通过,看到这个坑。。。。请绕道**
10.NSNotification API 改动:
**关于名字的使用采用了系统规定的方式:NSNotification.Name(rawValue:"自定义的名字")
NotificationCenter.default.removeObserver(self, name: NSNotification.Name(rawValue: KRLoginDoneNotification), object: nil)//3.0
NotificationCenter.default.removeObserver(self, name: KRLoginDoneNotification, object: nil)//2.3
DispatchQueue.global(qos: .userInitiated).async {}
dispatch_get_global_queue(0, 0).async {} // 2.3
dispatch_async(DispatchQueue.main{ }] //3.0
dispatch_async(dispatch_get_global_queue(0, 0)) {}//2.3
**dispatch_group的改动**
dispatch_group_leave(group) // 2.3
group.leave() // 3.0
12.第三方库采用3.0后的一些变化
1.MonkeyKing
MonkeyKing.shareMessage api 被 MonkeyKing.deliver 替换
总结:改动影响较大,但是并不复杂,利用xcode 自动转换功能就能解决大部分问题,主要包括关键字使用,系统api 修改
post_install do |installer|
installer.pods_project.targets.each do |target|
target.build_configurations.each do |config|
config.build_settings['SWIFT_VERSION'] = '3.0'
end
end
end
*待续*