I have Objective-C
Protocol
@protocol SomeObjCProtocol
- (BOOL) doSomethingWithError: (NSError **)error;
@end
And Swift
class
class SwiftClass : SomeObjCProtocol
{
func doSomething() throws {
}
}
Compilers gives me an error
Type 'SwiftClass' does not conform to protocol 'SomeObjCProtocol'"
Is there any solution how to get rid of this error?
I'm using XCode 7 Beta 4
When encountering that error message, one source of the problem might be that the Swift class conforming to the Objetive C protocol was not inherited from NSObject.
There are two problems:
func doSomething() throws
to the Objective-C method- (BOOL) doSomethingAndReturnError: (NSError **)error;
, which is different from your protocol method.@objc
attribute.There are two possible solutions:
Solution 1: Rename the Objective-C protocol method to
Solution 2: Leave the Objective-C protocol method as it is, and specify the Objective-C mapping for the Swift method explicitly: