swift代碼升級

本次升級由swift2.3->swift4.0swift

swift2.3升級swift3.0
pravite -> fileprivate
Publice -> open
枚舉更換小寫
方法名更精簡,後面括號移除api

gcd方法改變
gcdtimer建立方法返回值類型變了 DispatchSource -> DispatchSourceTimer
setTimer(start: DispatchTime.now() + Double(0) / Double(NSEC_PER_SEC), interval: interval * NSEC_PER_SEC, leeway: 0)
-> scheduleRepeating(deadline: .now(), interval: .seconds(interval))網絡

NS 去掉,AnyObject -> Any
字典用下標取值
let interfaceData = data as NSDictionary
currentSSID = interfaceData["SSID"] as! Stringide

-> 佈局

let interfaceData = data as Dictionary
currentMac = interfaceData.index(forKey: "BSSID" as NSObject) as! Stringpost

block須要@escaping修飾字體

自動佈局
snapkit
snp_ -> snp.ui

網絡請求
Alamofire
方法名更換,請求post\get
全部通知更換,枚舉更換小寫Notification.Task.DidCancel -> Notification.Name.Task.DidCancelspa

方法的第一個參數加_ ,調用時可省略參數名,不加則須要參數名code


一些屬性的名字改變isNetworkActivityIndicatorVisible 網絡請求的菊花
selecte -> isSelecte
hidden -> isHidden
等等

- - - - - - - - - - - - - - - - - - — - — - - - - - - - - —

swift3.0 - > swift 4.0

設備相機枚舉,類更細分
AVMetadataObjectTypeCode128Code -> AVMetadataObject.ObjectType.code128

AVCaptureSessionPreset1920x1080 -> AVCaptureSession.Preset.hd1920x1080

AVCaptureDevice.defaultDevice(withMediaType: AVMediaTypeVideo) -> AVCaptureDevice.default(for: AVMediaType.video)

不識別前邊下方會有紅色下劃線,提示更詳細替換

按command左鍵點擊代碼會有彈窗選擇進入類詳情或幫助,右鍵直接進詳情

#selector方法須要@objc修飾

The use of Swift 3 @objc inference in Swift 4 mode is deprecated警告
build setting swift3 @objc inference 設置爲off
提示信息能夠複製

MPI -> Double.pi π
字體屬性

全部通知名改成

NSNotification.Name.XXX.rawValue

相關文章
相關標籤/搜索