参数标签'(UUIDString)'与任何可用的重载都不匹配

时间:2017-01-04 09:38:16

标签: ios swift xcode swift3 uuid

我将我的代码转换为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)

1 个答案:

答案 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")
}