Reputation: 111
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?
Upvotes: 9
Views: 5921
Reputation:
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.
Upvotes: 5
Reputation: 19239
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.
Upvotes: 13