Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/list/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Swift 在维护列表中的域时-列表中的所有值都相同_Swift_List_Realm - Fatal编程技术网

Swift 在维护列表中的域时-列表中的所有值都相同

Swift 在维护列表中的域时-列表中的所有值都相同,swift,list,realm,Swift,List,Realm,我有两个数据模型,希望用加载的my json代码中的值填充它们,它有一个唯一的enter值数组。但在域中保存后,我得到了一个具有相同平均值的数组(等于原始数组中的最后一个值) 导入基础 导入RealmSwift 类数据:对象{ 动态变量city\u n:String=“” var templast=List() 动态变量更新\u d=NSDate() 重写静态func primaryKey()->字符串{ 返回“城市” } } 进口基金会 导入RealmSwift 类临时:对象{ 动态变量t:S

我有两个数据模型,希望用加载的my json代码中的值填充它们,它有一个唯一的enter值数组。但在域中保存后,我得到了一个具有相同平均值的数组(等于原始数组中的最后一个值)

<代码>导入基础 导入RealmSwift 类数据:对象{ 动态变量city\u n:String=“” var templast=List() 动态变量更新\u d=NSDate() 重写静态func primaryKey()->字符串{ 返回“城市” } } 进口基金会 导入RealmSwift 类临时:对象{ 动态变量t:String=“” } 以及一个填充它们的函数

Alamofire.request(.GET, URL , parameters: param)
                .responseJSON { response in
                    switch response.result {
                        case .Success:
                            if let value = response.result.value {
                                let json = JSON(value)
                                onlineLW.city_n = json["city"]["name"].stringValue
                                onlineLW.update_d = NSDate()
                                var temp_arr: [String] = []
                                for (_,subJson):(String, JSON) in json["list"] {
                                    ot.t = subJson["main"]["temp"].stringValue
                                    onlineLW.templst.append(ot)
                                    temp_arr.append(subJson["main"]["temp"].stringValue)
                                }
                                for var i = 1; i < temp_arr.count; i++ {
                                    onlineLW.templst[i].t = temp_arr[i]
                                    print("onlineLW.templst[i].t = \(onlineLW.templst[i].t)")
                                    print("temp_arr[i] = \(temp_arr[i])")
//                                    onlineLW.templst.append(ot)
                                }

                               print(onlineLW.templst)
                                try! self.realm.write {
                                    self.realm.add(onlineLW, update: true)
                                }
                               load.flag = true
                        }
                        case .Failure(let error):
                            print(error)
                    }
Alamofire.request(.GET,URL,参数:param)
.responseJSON{中的响应
开关响应。结果{
成功案例:
如果let value=response.result.value{
让json=json(值)
onlineLW.city_n=json[“city”][“name”].stringValue
onlineLW.update\u d=NSDate()
var temp_arr:[字符串]=[]
在JSON[“列表”]{
ot.t=subjectson[“main”][“temp”].stringValue
onlineLW.templast.append(ot)
临时附件(subjectson[“main”][“temp”].stringValue)
}
对于变量i=1;i
输出是相同元素的列表。可能是什么问题?谢谢

执行结果:

onlineLW.templst[i].t = 279.59
temp_arr[i] = 279.59
onlineLW.templst[i].t = 278.13
temp_arr[i] = 278.13
onlineLW.templst[i].t = 275.09
temp_arr[i] = 275.09
onlineLW.templst[i].t = 272.77
temp_arr[i] = 272.77
onlineLW.templst[i].t = 275.26
temp_arr[i] = 275.26
onlineLW.templst[i].t = 278.3
temp_arr[i] = 278.3
onlineLW.templst[i].t = 281.9
temp_arr[i] = 281.9
onlineLW.templst[i].t = 282.85
temp_arr[i] = 282.85
onlineLW.templst[i].t = 282.39
temp_arr[i] = 282.39
onlineLW.templst[i].t = 277.75
temp_arr[i] = 277.75
onlineLW.templst[i].t = 278.42
temp_arr[i] = 278.42
onlineLW.templst[i].t = 276.82
temp_arr[i] = 276.82
onlineLW.templst[i].t = 278.82
temp_arr[i] = 278.82
onlineLW.templst[i].t = 278.55
temp_arr[i] = 278.55
onlineLW.templst[i].t = 278.94
temp_arr[i] = 278.94
onlineLW.templst[i].t = 280.73
temp_arr[i] = 280.73
onlineLW.templst[i].t = 279.79
temp_arr[i] = 279.79
onlineLW.templst[i].t = 277.639
temp_arr[i] = 277.639
onlineLW.templst[i].t = 276.363
temp_arr[i] = 276.363
onlineLW.templst[i].t = 274.554
temp_arr[i] = 274.554
onlineLW.templst[i].t = 274.191
temp_arr[i] = 274.191
onlineLW.templst[i].t = 273.961
temp_arr[i] = 273.961
onlineLW.templst[i].t = 273.637
temp_arr[i] = 273.637
onlineLW.templst[i].t = 276.294
temp_arr[i] = 276.294
onlineLW.templst[i].t = 277.662
temp_arr[i] = 277.662
onlineLW.templst[i].t = 275.412
temp_arr[i] = 275.412
onlineLW.templst[i].t = 273.323
temp_arr[i] = 273.323
onlineLW.templst[i].t = 272.665
temp_arr[i] = 272.665
onlineLW.templst[i].t = 272.789
temp_arr[i] = 272.789
onlineLW.templst[i].t = 272.563
temp_arr[i] = 272.563
onlineLW.templst[i].t = 274.97
temp_arr[i] = 274.97
onlineLW.templst[i].t = 279.417
temp_arr[i] = 279.417
onlineLW.templst[i].t = 279.376
temp_arr[i] = 279.376
onlineLW.templst[i].t = 276.51
temp_arr[i] = 276.51
onlineLW.templst[i].t = 273.889
temp_arr[i] = 273.889
onlineLW.templst[i].t = 271.158
temp_arr[i] = 271.158
Data {
    city_n = Paris;
    update_d = 2016-02-12 09:27:31 +0000;
    templst = List<temp> (
        [0] temp {
            t = 271.158;
        },
        [1] temp {
            t = 271.158;
        },
        [2] temp {
            t = 271.158;
        },
        [3] temp {
            t = 271.158;
        },
        [4] temp {
            t = 271.158;
        },
        [5] temp {
            t = 271.158;
        },
        [6] temp {
            t = 271.158;
        },
        [7] temp {
            t = 271.158;
        },
        [8] temp {
            t = 271.158;
        },
        [9] temp {
            t = 271.158;
        },
        [10] temp {
            t = 271.158;
        },
        [11] temp {
            t = 271.158;
        },
        [12] temp {
            t = 271.158;
        },
        [13] temp {
            t = 271.158;
        },
        [14] temp {
            t = 271.158;
        },
        [15] temp {
            t = 271.158;
        },
        [16] temp {
            t = 271.158;
        },
        [17] temp {
            t = 271.158;
        },
        [18] temp {
            t = 271.158;
        },
        [19] temp {
            t = 271.158;
        },
        [20] temp {
            t = 271.158;
        },
        [21] temp {
            t = 271.158;
        },
        [22] temp {
            t = 271.158;
        },
        [23] temp {
            t = 271.158;
        },
        [24] temp {
            t = 271.158;
        },
        [25] temp {
            t = 271.158;
        },
        [26] temp {
            t = 271.158;
        },
        [27] temp {
            t = 271.158;
        },
        [28] temp {
            t = 271.158;
        },
        [29] temp {
            t = 271.158;
        },
        [30] temp {
            t = 271.158;
        },
        [31] temp {
            t = 271.158;
        },
        [32] temp {
            t = 271.158;
        },
        [33] temp {
            t = 271.158;
        },
        [34] temp {
            t = 271.158;
        },
        [35] temp {
            t = 271.158;
        },
        [36] temp {
            t = 271.158;
        }
    );
}
onlineLW.templast[i].t=279.59
温度arr[i]=279.59
onlineLW.tempst[i].t=278.13
温度arr[i]=278.13
onlineLW.tempst[i].t=275.09
温度arr[i]=275.09
onlineLW.tempst[i].t=272.77
温度arr[i]=272.77
onlineLW.tempst[i].t=275.26
温度arr[i]=275.26
onlineLW.templast[i].t=278.3
温度arr[i]=278.3
onlineLW.templast[i].t=281.9
温度arr[i]=281.9
onlineLW.tempst[i].t=282.85
温度arr[i]=282.85
onlineLW.tempst[i].t=282.39
温度arr[i]=282.39
onlineLW.tempst[i].t=277.75
温度arr[i]=277.75
onlineLW.tempst[i].t=278.42
温度arr[i]=278.42
onlineLW.tempst[i].t=276.82
温度arr[i]=276.82
onlineLW.tempst[i].t=278.82
温度arr[i]=278.82
onlineLW.tempst[i].t=278.55
温度arr[i]=278.55
onlineLW.tempst[i].t=278.94
温度arr[i]=278.94
onlineLW.tempst[i].t=280.73
温度arr[i]=280.73
onlineLW.tempst[i].t=279.79
温度arr[i]=279.79
onlineLW.templast[i].t=277.639
温度arr[i]=277.639
onlineLW.templast[i].t=276.363
温度arr[i]=276.363
onlineLW.tempst[i].t=274.554
温度arr[i]=274.554
onlineLW.tempst[i].t=274.191
温度arr[i]=274.191
onlineLW.templast[i].t=273.961
温度arr[i]=273.961
onlineLW.templast[i].t=273.637
温度arr[i]=273.637
onlineLW.tempst[i].t=276.294
温度arr[i]=276.294
onlineLW.templast[i].t=277.662
温度arr[i]=277.662
onlineLW.tempst[i].t=275.412
温度arr[i]=275.412
onlineLW.tempst[i].t=273.323
温度arr[i]=273.323
onlineLW.templast[i].t=272.665
温度arr[i]=272.665
onlineLW.tempst[i].t=272.789
温度arr[i]=272.789
onlineLW.templast[i].t=272.563
温度arr[i]=272.563
onlineLW.tempst[i].t=274.97
温度arr[i]=274.97
onlineLW.tempst[i].t=279.417
温度arr[i]=279.417
onlineLW.tempst[i].t=279.376
温度arr[i]=279.376
onlineLW.tempst[i].t=276.51
温度arr[i]=276.51
onlineLW.templast[i].t=273.889
温度arr[i]=273.889
onlineLW.tempst[i].t=271.158
温度arr[i]=271.158
资料{
城市=巴黎;
更新日期:2016-02-12 09:27:31+0000;
templst=列表(
[0]温度{
t=271.158;
},
[1] 临时工{
t=271.158;
},
[2] 临时工{
t=271.158;
},
[3] 临时工{
t=271.158;
},
[4] 临时工{
t=271.158;
},
[5] 临时工{
t=271.158;
},
[6] 临时工{
t=271.158;
},
[7] 临时工{
t=271.158;
},
[8] 临时工{
t=271.158;
},
[9] 临时工{
t=271.158;
},
[10] 临时工{
t=271.158;
},
[11] 临时工{
t=271.158;
},
[12] 临时工{
t=271.158;
},
[13] 临时工{
t=271.158;
},
[14] 临时工{
t=271.158;
},
[15] 临时工{
t=271.158;
},
[16] 临时工{
t=271.158;
},
[17] 临时工{
t=271.158;
},
[18] 临时工{
t=271.158;
},
[19] 临时工{
t=271.158;
},
[20] 临时工{
t=271.158;
},
[21]温度{
t=271.158;
},
[22]温度{
t=271.158;
},
[23]温度{
t=271.158;
},
[24]温度{
t=271.158;
},
[25]温度{
t=271.158;
},
[26]温度{
t=271.158;
},
onlineLW.templst[i].t = 279.59
temp_arr[i] = 279.59
onlineLW.templst[i].t = 278.13
temp_arr[i] = 278.13
onlineLW.templst[i].t = 275.09
temp_arr[i] = 275.09
onlineLW.templst[i].t = 272.77
temp_arr[i] = 272.77
onlineLW.templst[i].t = 275.26
temp_arr[i] = 275.26
onlineLW.templst[i].t = 278.3
temp_arr[i] = 278.3
onlineLW.templst[i].t = 281.9
temp_arr[i] = 281.9
onlineLW.templst[i].t = 282.85
temp_arr[i] = 282.85
onlineLW.templst[i].t = 282.39
temp_arr[i] = 282.39
onlineLW.templst[i].t = 277.75
temp_arr[i] = 277.75
onlineLW.templst[i].t = 278.42
temp_arr[i] = 278.42
onlineLW.templst[i].t = 276.82
temp_arr[i] = 276.82
onlineLW.templst[i].t = 278.82
temp_arr[i] = 278.82
onlineLW.templst[i].t = 278.55
temp_arr[i] = 278.55
onlineLW.templst[i].t = 278.94
temp_arr[i] = 278.94
onlineLW.templst[i].t = 280.73
temp_arr[i] = 280.73
onlineLW.templst[i].t = 279.79
temp_arr[i] = 279.79
onlineLW.templst[i].t = 277.639
temp_arr[i] = 277.639
onlineLW.templst[i].t = 276.363
temp_arr[i] = 276.363
onlineLW.templst[i].t = 274.554
temp_arr[i] = 274.554
onlineLW.templst[i].t = 274.191
temp_arr[i] = 274.191
onlineLW.templst[i].t = 273.961
temp_arr[i] = 273.961
onlineLW.templst[i].t = 273.637
temp_arr[i] = 273.637
onlineLW.templst[i].t = 276.294
temp_arr[i] = 276.294
onlineLW.templst[i].t = 277.662
temp_arr[i] = 277.662
onlineLW.templst[i].t = 275.412
temp_arr[i] = 275.412
onlineLW.templst[i].t = 273.323
temp_arr[i] = 273.323
onlineLW.templst[i].t = 272.665
temp_arr[i] = 272.665
onlineLW.templst[i].t = 272.789
temp_arr[i] = 272.789
onlineLW.templst[i].t = 272.563
temp_arr[i] = 272.563
onlineLW.templst[i].t = 274.97
temp_arr[i] = 274.97
onlineLW.templst[i].t = 279.417
temp_arr[i] = 279.417
onlineLW.templst[i].t = 279.376
temp_arr[i] = 279.376
onlineLW.templst[i].t = 276.51
temp_arr[i] = 276.51
onlineLW.templst[i].t = 273.889
temp_arr[i] = 273.889
onlineLW.templst[i].t = 271.158
temp_arr[i] = 271.158
Data {
    city_n = Paris;
    update_d = 2016-02-12 09:27:31 +0000;
    templst = List<temp> (
        [0] temp {
            t = 271.158;
        },
        [1] temp {
            t = 271.158;
        },
        [2] temp {
            t = 271.158;
        },
        [3] temp {
            t = 271.158;
        },
        [4] temp {
            t = 271.158;
        },
        [5] temp {
            t = 271.158;
        },
        [6] temp {
            t = 271.158;
        },
        [7] temp {
            t = 271.158;
        },
        [8] temp {
            t = 271.158;
        },
        [9] temp {
            t = 271.158;
        },
        [10] temp {
            t = 271.158;
        },
        [11] temp {
            t = 271.158;
        },
        [12] temp {
            t = 271.158;
        },
        [13] temp {
            t = 271.158;
        },
        [14] temp {
            t = 271.158;
        },
        [15] temp {
            t = 271.158;
        },
        [16] temp {
            t = 271.158;
        },
        [17] temp {
            t = 271.158;
        },
        [18] temp {
            t = 271.158;
        },
        [19] temp {
            t = 271.158;
        },
        [20] temp {
            t = 271.158;
        },
        [21] temp {
            t = 271.158;
        },
        [22] temp {
            t = 271.158;
        },
        [23] temp {
            t = 271.158;
        },
        [24] temp {
            t = 271.158;
        },
        [25] temp {
            t = 271.158;
        },
        [26] temp {
            t = 271.158;
        },
        [27] temp {
            t = 271.158;
        },
        [28] temp {
            t = 271.158;
        },
        [29] temp {
            t = 271.158;
        },
        [30] temp {
            t = 271.158;
        },
        [31] temp {
            t = 271.158;
        },
        [32] temp {
            t = 271.158;
        },
        [33] temp {
            t = 271.158;
        },
        [34] temp {
            t = 271.158;
        },
        [35] temp {
            t = 271.158;
        },
        [36] temp {
            t = 271.158;
        }
    );
}
for (_,subJson):(String, JSON) in json["list"] {
    let newOt = temp()
    newOt.t = subJson["main"]["temp"].stringValue
    onlineLW.templst.append(newOt)
    temp_arr.append(subJson["main"]["temp"].stringValue)
}