[英]Delegate method Between objective C class and swift class issue
I'm currently jumping into project built by different developer in swift over a year ago. 一年多以前,我目前正在迅速进入由其他开发人员构建的项目。 I'm aware swift changed through that time so there are few issues coming to me.
我知道那段时间变化很快,所以我遇到的问题很少。
There is beacon library calling delegate method in objective c class called: 信标库在目标c类中调用了委托方法:
- (void)beaconManager:(ESTBeaconManager *)manager
didRangeBeacons:(NSArray *)beacons
inRegion:(ESTBeaconRegion *)region;
and method that gets call from delegate in swift class: 和从swift类的委托获取调用的方法:
func beaconManager(manager: ESTBeaconManager, didRangeBeacons: [ESTBeacon], inRegion: ESTBeaconRegion) {
//code..
}
swift method compile with Error: 快速方法编译错误:
Objective-C method
beaconManager:didRangeBeacons:inRegion:
provided by methodbeaconManager(_:didRangeBeacons:inRegion:)
conflicts with optional requirement methodbeaconManager(_:didRangeBeacons:inRegion:)
in protocolESTBeaconManagerDelegate
Objective-C方法
beaconManager:didRangeBeacons:inRegion:
由方法beaconManager(_:didRangeBeacons:inRegion:)
提供,与协议ESTBeaconManagerDelegate
可选需求方法beaconManager(_:didRangeBeacons:inRegion:)
ESTBeaconManagerDelegate
Your method parameteres are optional, because in Objective-C you can pass a nil as an argument while you can not do that in Swift if the parameter is not optional. 您的方法参数是可选的,因为在Objective-C中,您可以传递nil作为参数,而如果参数不是可选的,则不能在Swift中这样做。 You need something like this.
您需要这样的东西。
func beaconManager(manager: ESTBeaconManager!, didRangeBeacons: [ESTBeacon]!, inRegion: ESTBeaconRegion!) {
//code..
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.