【发布时间】:2016-10-18 15:13:44
【问题描述】:
我在 swift 3 中遇到了一些协议问题。我的问题是当我有这个协议时:
@objc
protocol HHMapViewProtocol: class {
init()
func moveCamera(_ target: CLLocationCoordinate2D, zoom: Float, animated: Bool) -> Void
func moveCamera(_ target: CLLocationCoordinate2D, animated: Bool) -> Void
func positionCamera(on target: CLLocationCoordinate2D, facing at: CLLocationCoordinate2D, inDuration duration: CFTimeInterval)
func setWaypoints(_ waypoints: [CLLocationCoordinate2D])
}
此协议中的最后一个方法产生错误,因为:
Method cannot be a member of an @objc protocol because the type of
the parameter cannot be represented in Objective-C
我不明白为什么问题只出在数组中。如果我输入:
func setWaypoints(_ waypoints: [NSObject])
然后一切正常。为什么其他函数中的 CLLocationCoordinate2D 不是问题,而在数组情况下是问题?有人可以从 API 的角度给出一些不错的解决方案,因为我希望这个数组应该被参数化。我知道 CLLocationCoordinate2D 是一个结构,它不能在 Objective-C 中表示,但编译器不会抱怨 moveCamera 函数和 positionCamera。
【问题讨论】:
标签: objective-c swift3 swift-protocols