Swift Extensions from Objective-C Protocol -


so using objective-c library makes use of mkmapview. there class:

 @interface bsweathermapview : mkmapview     /** receiver’s delegate. */     @property (nonatomic, weak) id<bsweathermapviewdelegate> delegate;  

its protocol defined method:

    @protocol bsweathermapviewdelegate<mkmapviewdelegate>     @optional      - (mkannotationview *)mapview:(bsweathermapview *)mapview viewforannotation:(id<mkannotation >)annotation; 

my swift class has extension doing following:

extension viewcontroller : bsweathermapviewdelegate { func mapview(mapview: bsweathermapview!, viewforannotation annotation: anyobject) -> mkannotationview! {} } 

when following error: objective-c method mapview:viewforannotation: provided method mapview(_:viewforannotation:) conflicts optional requirement method mapview(_:viewforannotation:) in protocol mkmapviewdelegate

i have no clue how past this... anyone?

thanks,

the problem objective-c declaration illegal:

@protocol bsweathermapviewdelegate<mkmapviewdelegate> @optional  - (mkannotationview *)mapview:(bsweathermapview *)mapview viewforannotation:(id<mkannotation >)annotation; @end 

the illegality mkmapviewdelegate declares method called mapview:viewforannotation:, different first parameter type. there no overloading in objective-c, impossible distinguish between mkmapviewdelegate mapview:viewforannotation: , bsweathermapviewdelegate mapview:viewforannotation:. if same app try implement both, runtime have no way of knowing which.

the objective-c compiler doesn't stop long don't try implement both methods; warns not error. (you, while writing app in objective-c, have presumably been blithely ignoring warning; mistake, have clued in fact in trouble.) if had tried implement both, have gotten "duplicate declaration" compile error.

but swift compiler, can tell difference between them because does permit overloading, more proactive , stops implementing either of them. thus, can never implement either of them on swift side.

your choices, therefore, are:

  • abandon use of library, faulty.

  • fix library legal (assuming have access source). example, change name of bsweathermapviewdelegate method wherever occurs.

  • implement these delegate methods in objective-c, not in swift.


Comments

Popular posts from this blog

wordpress - (T_ENDFOREACH) php error -

Export Excel workseet into txt file using vba - (text and numbers with formulas) -

Using django-mptt to get only the categories that have items -