我将代码转换为swift3。出现以下错误:
参数标签'(UUIDString)'与任何可用的重载都不匹配
locationManager.delegate = self
if (CLLocationManager.authorizationStatus() != CLAuthorizationStatus.authorizedWhenInUse) {
locationManager.requestWhenInUseAuthorization()
}
let region = CLBeaconRegion(proximityUUID: UUID(UUIDString: "E2C56DB5-DFFB-48D2-B060-D0F5A71096E0"), identifier: "ru.techmas.techbeacon")
locationManager.startRangingBeaconsInRegion(region)
有人知道这个错误吗? (我的Xcode版本是8.2)
最佳答案
UUID
的初始化程序更改为init?(uuidString:)
,因此将参数标签更改为uuidString
,并且它返回可选的UUID?
实例,因此您需要包装该可选实例。
let region = CLBeaconRegion(proximityUUID: UUID(uuidString: "E2C56DB5-DFFB-48D2-B060-D0F5A71096E0")!, identifier: "ru.techmas.techbeacon")
您还可以选择使用
if let
而不是强制包装来打开可选包装。if let uuidStr = UUID(uuidString: "E2C56DB5-DFFB-48D2-B060-D0F5A71096E0") {
let region = CLBeaconRegion(proximityUUID: uuidStr, identifier: "ru.techmas.techbeacon")
}
关于ios - 参数标签'(UUIDString)'与任何可用的重载都不匹配,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/41460531/