iphone - 类型 "[String : String]"的值没有成员 'major'

标签 iphone string swift types ibeacon

当我想在我的字典中添加 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)
        }
    }
}

最佳答案

这一行

var beacons: [Dictionary<String, String>] = []

正在隐藏您的原始信标数组。这意味着在定义它的范围内(for 循环的主体),编译器认为信标始终引用字典数组。简单的答案就是重命名它:

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)
    }
}

关于iphone - 类型 "[String : String]"的值没有成员 'major',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35426450/

相关文章:

ios - 制作像 iTunes 专辑页面这样的页面的最佳方法是什么?

iphone - 在 RootController 上调整 UITableView 的大小

c# - 在 C# 中将字符串转换为图像

ios - 如何在 swift 中从 childViewContoller 刷新 parentViewContoller?

iphone - 我如何知道是否正在显示 ModalViewController?

iphone - 寻找循环引用

c - 无法找出我的代码中的逻辑错误

java - 每次遇到字符时,在数组列表中拆分字符串

string - Unicode 字符串插值

ios - 什么会使UIViewController暂时变得无响应?