“[String : String]”类型的值没有成员 'major'
Value of type "[String : String]" has no member 'major'
当我想在我的字典中添加 String(beacons[index].major.stringValue)
时,出现以下错误:
Value of type "[String : String]" has no member 'major'
if(beacons.count > 0) {
let nearestBeacon:CLBeacon = beacons[0]
for var index = 0; index < beacons.count; index++ {
let uuidString = "00000000-0000-0000-0000-000000000000"
var beacons: [Dictionary<String, String>] = []
beacons.append(["uuid": uuidString, "major": String(beacons[index].major.stringValue), "minor": beacons[index].minor.stringValue, "accurency": String(beacons[index].accuracy)])
Server.beaconsSend(beacons) { // success, data in
print(data)
}
}
}
可能是因为您在信标数组上处于某个条件(如果有)时创建了信标字典。
你创建的beacons现在隐藏了beacon数组,你只引用字典
这一行
var beacons: [Dictionary<String, String>] = []
正在隐藏您原来的 beacons
阵列。这意味着在它定义的范围内(for 循环的主体),编译器认为 beacons
总是引用字典数组。简单的答案就是重命名它:
for var index = 0; index < beacons.count; index++ {
let uuidString = "00000000-0000-0000-0000-000000000000"
var myBeacons: [Dictionary<String, String>] = []
myBeacons.append(["uuid": uuidString, "major": String(beacons[index].major.stringValue), "minor": beacons[index].minor.stringValue, "accurency": String(beacons[index].accuracy)])
Server.beaconsSend(myBeacons) { // success, data in
print(data)
}
}
当我想在我的字典中添加 String(beacons[index].major.stringValue)
时,出现以下错误:
Value of type "[String : String]" has no member 'major'
if(beacons.count > 0) {
let nearestBeacon:CLBeacon = beacons[0]
for var index = 0; index < beacons.count; index++ {
let uuidString = "00000000-0000-0000-0000-000000000000"
var beacons: [Dictionary<String, String>] = []
beacons.append(["uuid": uuidString, "major": String(beacons[index].major.stringValue), "minor": beacons[index].minor.stringValue, "accurency": String(beacons[index].accuracy)])
Server.beaconsSend(beacons) { // success, data in
print(data)
}
}
}
可能是因为您在信标数组上处于某个条件(如果有)时创建了信标字典。 你创建的beacons现在隐藏了beacon数组,你只引用字典
这一行
var beacons: [Dictionary<String, String>] = []
正在隐藏您原来的 beacons
阵列。这意味着在它定义的范围内(for 循环的主体),编译器认为 beacons
总是引用字典数组。简单的答案就是重命名它:
for var index = 0; index < beacons.count; index++ {
let uuidString = "00000000-0000-0000-0000-000000000000"
var myBeacons: [Dictionary<String, String>] = []
myBeacons.append(["uuid": uuidString, "major": String(beacons[index].major.stringValue), "minor": beacons[index].minor.stringValue, "accurency": String(beacons[index].accuracy)])
Server.beaconsSend(myBeacons) { // success, data in
print(data)
}
}