Swift class does not conform to Objective-C protocol with error handling -
i have objective-c
protocol
@protocol someobjcprotocol - (bool) dosomethingwitherror: (nserror **)error; @end
and swift
class
class swiftclass : someobjcprotocol { func dosomething() throws { } }
compilers gives me error
type 'swiftclass' not conform protocol 'someobjcprotocol'"
is there solution how rid of error? i'm using xcode 7 beta 4
there 2 problems:
- swift 2 maps
func dosomething() throws
objective-c method- (bool) dosomethingandreturnerror: (nserror **)error;
, different protocol method. - the protocol method must marked "objective-c compatible"
@objc
attribute.
there 2 possible solutions:
solution 1: rename objective-c protocol method to
@protocol someobjcprotocol - (bool) dosomethingandreturnerror: (nserror **)error; @end
solution 2: leave objective-c protocol method is, , specify objective-c mapping swift method explicitly:
@objc(dosomethingwitherror:) func dosomething() throws { // stuff }
Comments
Post a Comment