IPhone : Issue with conforming to Objective-C protocol from Swift NSObject subclass

on Wednesday, February 25, 2015

This piece of code works absolutely fine in Swift 1.1



// Obj-C

@import Foundation;

@protocol HashableObject <NSObject>
- (NSUInteger)hash;
@end

// Swift

import Foundation

@objc class Object: NSObject, HashableObject {

func hash() -> UInt {
return 0
}
}


However, in latest Swift 1.2 and XCode 6.3beta2 the compiler complains that Method 'hash()' overrides Objective-C method 'hash' from superclass 'NSObject'


Is that a bug, or something else has fundamentally changed and the code is wrong? Are there any workarounds to this? I have numerous things in my code that need to conform to certain protocols from Objective-C libraries and this essentially breaks everything with no apparent solution other than wait for the next Swift release.


0 comments:

Post a Comment