- 帶參數(shù)的函數(shù)飒筑,都加入了 _ 省略參數(shù)名的標(biāo)記
func log(_ info:String) {} // 3.0
func log(info:String) {} //2.3
類&類成員說(shuō)明public 關(guān)鍵字變成open
函數(shù)說(shuō)明privite 關(guān)鍵字變成 fileprivate
枚舉定義的case 語(yǔ)法字段命名不支持大寫開頭黎比,統(tǒng)一采用小寫
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 的類實(shí)現(xiàn)
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 改動(dòng)較多
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 被自動(dòng)替換:這里有坑
private lazy var __once: () = {
let pagesContainerHeight = SwiftPages.frame.size.height - SwiftPages.yOrigin - SwiftPages().distanceToBottom
}() // 3.0 錯(cuò)誤的轉(zhuǎn)換,看不懂的語(yǔ)法
override public func drawRect(rect: CGRect) {
dispatch_once(&token) {
let pagesContainerHeight = self.frame.height - self.yOrigin - self.distanceToBottom
}
}//2.3
**這里有點(diǎn)坑啊 ,轉(zhuǎn)換的代碼完全看不懂缩宜,self 被類本身替換肘迎,drawRect方法也被替換掉了,然后編譯不通過(guò)锻煌,看到這個(gè)坑妓布。。炼幔。秋茫。請(qǐng)繞道**
10.NSNotification API 改動(dòng):
**關(guān)于名字的使用采用了系統(tǒng)規(guī)定的方式: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的改動(dòng)**
dispatch_group_leave(group) // 2.3
group.leave() // 3.0
12.第三方庫(kù)采用3.0后的一些變化
1.MonkeyKing
MonkeyKing.shareMessage api 被 MonkeyKing.deliver 替換
總結(jié):改動(dòng)影響較大,但是并不復(fù)雜乃秀,利用xcode 自動(dòng)轉(zhuǎn)換功能就能解決大部分問(wèn)題肛著,主要包括關(guān)鍵字使用,系統(tǒng)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
*待續(xù)*