Swift 1.2 / Xcode 6.3


#1

As you may know, Swift 1.2 is out.

It broke some of my current projects, like we cannot do this anymore:

extension A {
  func setProperty(str: String) { }
}
// error: method ‘setProperty’
// redeclares Objective-C method
//'setProperty:’

(“Swift now detects discrepancies between overloading and overriding in the Swift type system and the effective behavior seen via the Objective-C runtime. (18391046, 18383574)”)

It seems that there are a lot of improvements…

Here goes my question, a “new Set data structure is included which provides a generic collection of unique elements, with full value semantics. It bridges with NSSet, providing functionality analogous to Array and Dictionary. (14661754)

Because of that, some method signatures have changed (e.g.: touchesBegan:withEvent:) (GameScene.swift, line 98):

override func touchesBegan(touches: NSSet, withEvent event: UIEvent) {
    if let touch = touches.anyObject() as UITouch? {
    ...

I fixed like this:

override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
    if let touch = touches.first as? UITouch {
    ...

@PaulSolt, would this be a correct way to handle UITouches in Swift 1.2? Thanks.


#2

It’s been on my mind all day. I just blogged about it.

I think I’ll be doing all future videos with Xcode 6.3 beta (until it’s public), since it’s a breaking change to the language.

Yes that’s the best way to do it. In my post I show that code along with some other places that require changes.


#3

Awesome, thanks.

I think I’ll be doing all future videos with Xcode 6.3 beta (until it’s public), since it’s a breaking change to the language.

+1 to that! Otherwise we would be creating broken projects from the start. :smiley:

BTW Nice blog post. I really like the new “combine multiple “if let” values”. Swift is getting better and better. These are exciting times. :iphone: :ok_hand:


#4

By the way I remember seeing this on the RW’s website:

func touchesBegan(touches: [UITouch]!, withEvent event: UIEvent!)

This way you don’t have to downcast.

Not sure if there is a problem with it now…


#5

Unfortunately that doesn’t work anymore.


#6

Oh, Well !
Mazel Tov ! :smiley:


#7

Have you tried: “There’s a new menu option: Edit\Convert\To Swift 1.2” ? :wink:

Also I just love this:

let longEdge: CGFloat
 
if isLandscape {
  longEdge = image.calculateWidth()
} else {
  longEdge = image.calculateHeight()
}
 
// you can access longEdge from this point on

This was a thorn in my eye ! :slight_smile: I can finally declare my constants as I wish :smile:
Also the multiple if statements, rather then nesting ? :slight_smile: yaya :smiley:


#8
  1. I mentioned the Convert in the end of the post. My experience was that it wasn’t good enough. For a simple project it didn’t help me fix the code automatically. I had to manually change things.

  2. I’m not sure if I recommend it (the converter to Swift 1.2) yet, and will have to play with it more.

  3. Yes the constant declaration versus assignment is also something I should have mentioned. That’s amazing!


#9

Great looking upgrades, but this is an unusual and difficult situation because 6.2 isn’t even out of beta yet, so it could be a long time before we’re allowed to submit any apps created with 6.3! You can either be on the leading edge now but unable to submit apps, or be using the older version and have to convert everything later. Either way half the books and courses you’re following will be wrong.

I will stick with 6.2beta for now (not 6.1 only because I’m making a Watch app), and I guess Paul will need to flag the differences throughout the course because not everyone will be using the same version of Swift until things have settled down.


#10

In method Overloading, two or more methods shares the same name in the same class but having different signature while in method overriding, method of parent class is re-defined in the inherited class having same signature.

In the case of performance, method overloading gives better performance when compared to overriding because the binding of overridden methods is being done at runtime.

Static binding is happens when method overloaded while dynamic binding happens when method overriding.

Method overloading add or extend more to the method functionality while method overloading is to change the existing functionality of the method…Source

Dov