我正在开发一款iOS应用,它可以覆盖一个区域内的信标。我有一个CLLocationManager委托,它定期从区域内的所有信标中获取信息。我有一个for循环,循环遍历所有找到的信标并将数据打印到控制台。
for i in 0..<knownBeacons.count{
var uuid = knownBeacons[i].proximityUUID.description
println(uuid)
}
但是,当我打印每个信标的UUID描述时,它会添加其他信息。例如,print语句返回:
<__NSConcreteUUID 0x1700351e0> B9407F30-F5F8-466E-AFF9-25556B57FE6D
我真正想要的只是最后一部分'B9407F30-F5F8-466E-AFF9-25556B57FE6D',并希望删除&lt; &GT;括号。谁能告诉我怎么做?或者如果我不应该使用UUID.description属性并且应该使用其他东西。感谢。
更新:为了清楚起见,我已经包含了完整的ViewController类
class ViewController: UIViewController, CLLocationManagerDelegate {
let locationManager = CLLocationManager()
let region = CLBeaconRegion(proximityUUID: NSUUID(UUIDString: "B9407F30-F5F8-466E-AFF9-25556B57FE6D"), identifier: "Estimotes")
override func viewDidLoad() {
super.viewDidLoad()
locationManager.delegate = self;
if(CLLocationManager.authorizationStatus() != CLAuthorizationStatus.AuthorizedWhenInUse){
locationManager.requestWhenInUseAuthorization()
}
locationManager.startRangingBeaconsInRegion(region)
locationManager.startUpdatingLocation()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func locationManager(manager: CLLocationManager!, didRangeBeacons beacons: [AnyObject]!, inRegion region: CLBeaconRegion!){
let knownBeacons = beacons.filter{ $0.proximity != CLProximity.Unknown }
if(knownBeacons.count > 3) {
for i in 0..<3{
var uuid = knownBeacons[i].proximityUUID
var major = knownBeacons[i].major
var minor = knownBeacons[i].minor
var proximity = knownBeacons[i].proximity.rawValue
var rssi = knownBeacons[i].rssi
var accuracy = knownBeacons[i].accuracy.description
println(uuid)
}
}
}
}
答案 0 :(得分:4)
var uuid = knownBeacons[i].proximityUUID!.UUIDString