swift代碼升級


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

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

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! String

->

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

block需要@escaping修飾

自動布局
snapkit
snp_ -> snp.

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

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


一些屬性的名字改變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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM