SagarSDagdu / SDBeaconScanner

SDBeaconScanner is a Swift library for scanning Bluetooth beacons using CoreLocation's beacon ranging API. It simplifies scanning for beacons by providing an easy-to-use API with support for UUID, major, and minor identifiers.
MIT License
1 stars 0 forks source link

Change signature of closure to use Result type #2

Closed edorphy closed 2 months ago

edorphy commented 2 months ago

Since this framework uses closures instead of structured concurrency, I would highly recommend that you change the closure signature to use the Swift Result type.

from: public typealias BeaconScanningCompletion = ([Beacon], Error?) -> Void

to: public typealias BeaconScanningCompletion = (Result<[Beacon], BeaconErrorType>) -> Void

Why? Smart API signatures that do not inherit legacy objective-c style.

Either you should have beacons, or you should have an error. This also lets you constrain the error type so you don't need to typecast in your error handling code. It is really, beacons, or a specific domain error that you control.

SagarSDagdu commented 2 months ago

Hi @edorphy, thanks for the inputs! I will surely consider your suggestions in the next release. 👍🏻