Swift PureMVC : Does not conform to NSObjectProtocol
Asked Answered
S

2

9

I want to manage all location code in one of my Proxy classes. As the class is built from scratch and not built on a UIView or similar class that inherits NSObjectProtocol, it throws an error 'Does not conform to protocol NSObjectProtocol when I am trying to add CLLocationManagerDelegate.

class GeoProxy : Proxy, CLLocationManagerDelegate
{
   var locationManager = CLLocationManager()

   override class var NAME: String { return "GeoProxy" }
}

Any idea, how I get the class to conform without adding all NSObjectProtocol functions?

Straightforward answered 14/12, 2015 at 12:44 Comment(0)
L
13

Easier way is making Proxy class inherit from NSObject:

class Proxy: NSObject {
}

Then, all subclasses will conform to NSObjectProtocol. In addition, these classes will be compatible with Objective-C code.

Lesbianism answered 14/12, 2015 at 12:47 Comment(2)
I need Swift. But okay. Cool did it on the Notifier class level.Straightforward
import Foundation public class Notifier : NSObject, INotifier {Straightforward
E
5

It's best to put CLLocationManagerDelegate related code in a viewComponent (UIViewController) and handle things from there, UIViewController is already inherited from NSObject so there's no need to change core actors of PureMVC (Notifier in this case).

Another option is to create an independent class to manage location related activities, for instance instantiate a Mediator LocationMediator instantiating class Location: NSObject, CLLocationManagerDelegate as it's viewComponent and setting itself as a delegate via ILocation protocol.

LocationMediator would listen to any events from it's viewComponent via ILocation delegate and it would then send a notification that other interested actors can respond to.

Hardware related activity belongs to View

Any hardware related activity for instance Camera, GPS, Accelerometer, Gyroscope and non-hardware elements like Router in a browser typically generate events and belong to view tier of the MVC paradigm and should be handled inside a view component. Any triggered events within viewComponents are then handled by it's mediator if it needs to communicate to the other parts of the system. Proxy is best suited for web services or persistence.

Errecart answered 27/3, 2016 at 15:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.