[英]Swift PureMVC : Does not conform to NSObjectProtocol
I want to manage all location code in one of my Proxy classes. 我想在我的一个Proxy类中管理所有位置代码。 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
. 由于该类是从头开始构建的,而不是构建在继承
NSObjectProtocol
的UIView
或类似类上,因此当我尝试添加CLLocationManagerDelegate
时,它会抛出错误“不符合协议NSObjectProtocol
。
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? 任何想法,如何在不添加所有
NSObjectProtocol
函数的情况下使类符合要求?
Easier way is making Proxy
class inherit from NSObject
: 更简单的方法是使
Proxy
类继承自NSObject
:
class Proxy: NSObject {
}
Then, all subclasses will conform to NSObjectProtocol
. 然后,所有子类都符合
NSObjectProtocol
。 In addition, these classes will be compatible with Objective-C code. 此外,这些类将与Objective-C代码兼容。
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). 最好将
CLLocationManagerDelegate
相关代码放在viewComponent
( UIViewController
)中并从那里处理东西,UIViewController已经从NSObject
继承,因此不需要更改PureMVC的核心参与者(在这种情况下为Notifier
)。
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. 另一种选择是创建一个独立的类来管理与位置相关的活动,例如实例化一个Mediator
LocationMediator
实例化class Location: NSObject, CLLocationManagerDelegate
作为它的viewComponent并通过ILocation
协议将自己设置为委托。
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. LocationMediator
会听从它通过的viewComponent任何事件ILocation
代表,然后它会发送其他感兴趣者可以响应的通知。
Hardware related activity belongs to View 硬件相关活动属于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. 任何与硬件相关的活动,例如摄像头,GPS,加速度计,陀螺仪和浏览器中的非硬件元件(如路由器)通常会生成事件并属于MVC范例的视图层,应在视图组件内处理。 Any triggered events within viewComponents are then handled by it's mediator if it needs to communicate to the other parts of the system.
如果viewComponents中的任何触发事件需要与系统的其他部分进行通信,则它们将由其中介处理。
Proxy
is best suited for web services or persistence. Proxy
最适合Web服务或持久性。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.