Wednesday Discount - Lifetime Access for $20!!!! - Click Here!

Minor Changes in Xcode 7.3 and Swift 2.2

Minor Changes in Xcode 7.3 and Swift 2.2
March 24, 2016 Justin

Minor Changes in Xcode 7.3 and Swift 2.2

So now that we’re in a post-Xcode 7.3 / Swift 2.2 world, I’m going through our past projects and seeing what needs tweaking.  So far Xcode’s suggested “Fix-It” prompt cleans up nearly everything I’ve come across*. And even if you do nothing, every project I’ve checked so far still builds fine. Yee-haw (kicks heels).  Just a lot yellow warnings, no red errors.  So if you’re working on something and suddenly, get a yellow warning, you can probably just let it mellow. Or let Xcode fix it.

So far here’s what I’ve encountered in a wide range of Sprite Kit projects….

What you’ll read…

‘++’ is deprecated: it will be removed in Swift 3

What you’ll see…

++ is deprecated

What to do….

Let Xcode fix it. For example…

i++

would now be…

i += 1

What you’ll read…

C-style for statement is deprecated and will be removed in a future version of Swift

What you’ll see…

C-style for statement is deprecated and will be removed in a future version of Swift

What to do….

Let Xcode fix it. For example…

for ( var i:Int = 0;  i < 100;  i++)

would now be…

for i:Int in 0 ..< 100

or even simpler….

for i in 0 … 99

I know, its SO cute now huh.  Its like an emoji version of a for statement.

*Footnote

If Xcode leaves in the parenthesis from the original for statement, just take those out.

 

What you’ll read…

No method declared with Objective-C selector ‘blah blah blah:’

What you’ll see…

Is something like this…

No method declared with Objective-C selector

What to do….

Let Xcode fix it. For example…

swipeLeftRec.addTarget(self, action: “swipedLeft”)

would now be…

swipeLeftRec.addTarget(self, action: Selector(“swipedLeft”))

 

 

What you’ll read…

Use of string literal for Objective-C selectors is deprecated; use ‘#selector’ instead

What you’ll see…

Is something like this…

Use of string literal for Objective-C selectors is deprecated; use '#selector' instead

What to do….

Let Xcode fix it. For example, this snippet…

selector: “playBackgroundSound:”

would now be…

selector: #selector(GameViewController.playBackgroundSound(_:))

 

 

*Another footnote 

Xcode 7.3 / Swift 2.2 clearly wanted to update the selectors for gesture recognizer targets, but just couldn’t quite close the deal. Granted,  I only noticed this happening some of the time Xcode auto-updated gesture recognizer targets.  So for example, it updated the code from this…

panRec.addTarget(self, action:”panned:”)

to this…

panRec.addTarget(self, action: Selector(“panned:”))

but really it should be this…

panRec.addTarget(self, action: #selector(Page.panned(_:) ))

The project builds fine either way (as it has so far with every un-updated line of code I’ve come across) but the warning is still there with the gesture recognizer targets.

 




Know what an affiliate program is? You make money just by sharing links to our site! Win. Win.

Earn when you refer any buyer here! 30 day tracking. Commissions are 33%-50% and recur on subscription products!