Swift 3 and Swift 2.3 change

前端之家收集整理的这篇文章主要介绍了Swift 3 and Swift 2.3 change前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

One case:

1)when swift 3 to swift 2.3,just remove “_” before parameter,
correspondingly when swift 2.3 to swift 3,just add “_” before parameter,

Example:
Swift3:
typealias LMLocationCompletionHandler = ((_ latitude:Double,_ longitude:Double,_ status:String,_ verboseMessage:String,_ error:String?)->())?

Swift2.3
typealias LMLocationCompletionHandler = ((latitude:Double,longitude:Double,status:String,verboseMessage:String,error:String?)->())?

2) add fileprivate or remvoe before defining Variables and methods
swift 3 : fileprivate var reverseGeocodingCompletionHandler:
swift 2.3 : var reverseGeocodingCompletionHandler:
3)
Sometimes,need reset parameters
like this CLAuthorizationStatus.NotDetermined:
just reselect NotDetermined will fix “have no member” error
4) valueForKey - value
Swift 3:
resultDict.value(forKey: “results”) as! NSArray
Swift 2.3:
resultDict.valueForKey(“results”) as! NSArray
5)method object - objectForKey
Swift 3:
locationDict.object(forKey: “formatted_address”) as! NSString
Swift 2.3
locationDict.objectForKey(“formatted_address”) as! NSString

6)NSArray’s indexOfObject
Swift 3:
inArray.indexOfObject(passingTest:)
Swift 2.3

7)
Swift 3:
let urlwithPercentEscapes = myurlstring.addingPercentEncoding( withAllowedCharacters: .urlQueryAllowed)
Swift 2.3:
let urlwithPercentEscapes = myurlstring.stringByAddingPercentEncodingWithAllowedCharacters( NSCharacterSet.URLQueryAllowedCharacterSet())

the difference are parameters’s first character is not same. maybe changed from lower case to upper case

原文链接:https://www.f2er.com/swift/322890.html

猜你在找的Swift相关文章