I was revisiting an older Swift 1.0 project this morning, and discovered that, in the upgrade to Swift 2.0, it had become hilariously uncompilable. The automatic converter worked, frankly, better than I expected, but I was still left with a couple of head-scratching errors. The most confusing was that my SpriteKit subclasses no longer seemed to override their parent UIResponder methods:
My touches*
methods don’t seem to have the right signature anymore. Turns out, I’d implemented them all as:
1
2
3
4
5
|
override func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent) {
if let touch = touches.first as! UITouch {
// Do something with touch
}
}
|
Either Swift 1.1 was more relaxed when it came to matching method signatures or the signatures of these methods changed in iOS 9, because the solution turned out to be to change the method signatures to take a set of UITouch objects and an optional event, e.g.:
1
2
3
4
5
|
override func touchesBegan(touches: Set<UITouch>, withEvent event: UIEvent?) {
if let touch = touches.first {
// Do something with touch
}
}
|
Leave a Reply