Delegate method Between objective C class and swift class issue

时间:2015-05-04 19:37:13

标签: ios objective-c iphone xcode swift

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:

- (void)beaconManager:(ESTBeaconManager *)manager
      didRangeBeacons:(NSArray *)beacons
             inRegion:(ESTBeaconRegion *)region;

and method that gets call from delegate in swift class:

func beaconManager(manager: ESTBeaconManager, didRangeBeacons: [ESTBeacon], inRegion: ESTBeaconRegion) {
    //code..
}

swift method compile with Error:

Objective-C method beaconManager:didRangeBeacons:inRegion: provided by method beaconManager(_:didRangeBeacons:inRegion:) conflicts with optional requirement method beaconManager(_:didRangeBeacons:inRegion:) in protocol ESTBeaconManagerDelegate

1 个答案:

答案 0 :(得分:0)

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. You need something like this.

func beaconManager(manager: ESTBeaconManager!, didRangeBeacons: [ESTBeacon]!, inRegion: ESTBeaconRegion!) {
    //code..
}