Difficulties Converting to Swift 3

After converting from Swift 2 to Swift 3 (even after converting edit-> convert → to the current fast syntax), I get a lot of errors. Special:

<w640 "

I am shown a total of 90 errors for my project that worked perfectly in Swift 2 before I downloaded this Xcode 8.0 beta code and converted to Swift 3

Is this a conversion error?

+47
ios10 swift swift3 xcode8
Jun 21 '16 at 14:15
source share
3 answers

Most of them are simple fixes just by clicking the red button, and Xcode will fix it for you! Others include:

Cgect

Swift 2:

let frame = CGRectMake(0, 0, 20, 20) 

Swift 3:

 let frame = CGRect(x: 0, y: 0, width: 20, height: 20) 

Cgpoint

Swift 2:

 let point = CGPointMake(0, 0) 

Swift 3:

 let point = CGPoint(x: 0, y: 0) 

Cgsize

Swift 2:

 let size = CGSizeMake(20, 20) 

Swift 3:

 let size = CGSize(width: 20, height: 20) 

CGRectGetMidX

Swift 2:

 CGRectGetMidX(view) 

Swift 3:

 view.midX 

CGRectGetMidY

Swift 2:

 CGRectGetMidY(view) 

Swift 3:

 view.midY 

Uicolor

Swift 2:

 let color = UIColor.redColor() 

Swift 3:

 let color = UIColor.red 

"NS"

Swift 2:

 NSTimer NSData NSError 

Swift 3:

 Timer Data Error 

UserDefaults

Swift 2:

 NSUserDefaults.standardUserDefaults().//something 

Swift 3:

 UserDefaults.standard.//something 
+184
Jun 21 '16 at 16:57
source share

And always remember to use the useful function "Fix all in Scope", which can be found in the editor → Fix all in Scope

+12
Oct 12 '16 at 10:11
source share

I converted the project, and Xcode did not help me with any corrections, so I resorted to finding and replacing regular expressions: -

 CGPointMake\((.*),[ ]*([^\)]+)\) CGPoint(x:$1, y:$2) CGSizeMake\((.*),[ ]*([^\)]+)\) CGSize(width:$1, height:$2) 

Please note that they do not know the enclosed parentheses, but are probably good enough for 90% of cases.

+1
Jan 03 '17 at 12:06 on
source share



All Articles