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

posted @ 2017-09-18 16:50  JustToGo  阅读(1693)  评论(0编辑  收藏  举报