我将我的代码转换为swift 3.我得到了以下错误:
参数标签'(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)
答案 0 :(得分:0)
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")
}