3

Attempting do something similar to an abstract class in swift using protocols and extensions to better organize a pluggable class so that it can be swapped out manually if needed, for example a different map api. The issue is once I add the protocol to the main class and run it the delegate functions extended in the protocol are ignored.

so for example

protocol MapTwoDelegate:BaseMapProtocol,RequiredMapViewDelegate{{
    var someVariable:String!{get set}
}

extension MapTwoDelegate:BaseMapProtocol{
    //MARK:Map Functions
    func mapView(mapView: CoolMapView, annotationCanShowCallout annotation: CoolAnnotation) -> Bool {
        return //Something
    }

The only fix is to extend what ever class I am extending directly; however, If i switched apis, in this case mapping api, then I would have to comment out the swift file.

Any assistance or insight would be well appreciated?

also just to add I extended it instead of making it a class because, their are variables and functions I would want the user to create and are slightly different among implementations

kdgwill
  • 2,129
  • 4
  • 29
  • 46
  • 2
    Could you clarify your question? I did up-vote because I think this is an interesting topic, but I think this question could be improved to comply with [mcve] – Dan Beaulieu Jan 08 '16 at 16:25
  • Could you describe the classes and their protocol usage a bit more. I tried various combinations of this and could not get it to NOT work. Also, if your app only has one variation of your RequiredMapViewDelegate at any given time, you should consider extending it directly instead of extending the base protocol. (i.e. just extend whatever protocol you chose MapTwoDelegate to inherit from – Alain T. Jan 19 '16 at 04:34

0 Answers0