简体   繁体   中英

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:

- (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

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..
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM