【发布时间】:2018-07-24 06:17:09
【问题描述】:
当我的数字数组像 -> ["1","2","3","4","5","6","7"]
let numbers = ["1","2","3","4","5","6","7"]
let chunkSize = 2
let chunks = stride(from: 0, to: numbers.count, by: chunkSize).map {
Array(numbers[$0..<min($0 + chunkSize, numbers.count)])
}
// prints as [["1", "2"], ["3", "4"], ["5", "6"], ["7"]]
但是当我的数字数组是这样的时候
(
{
"facility_id" = 1;
"options_id" = 3;
},
{
"facility_id" = 3;
"options_id" = 12;
},
{
"facility_id" = 2;
"options_id" = 7;
},
{
"facility_id" = 3;
"options_id" = 12;
},
{
"facility_id" = 2;
"options_id" = 6;
},
{
"facility_id" = 1;
"options_id" = 4;
}
)
它正在显示此错误:
无法将“CountableRange”类型的值转换为预期的参数类型“Int”
【问题讨论】:
-
将 numbers 数组更改为 [{'id':1},{'id':2},{'id':3},{'id':4 时的预期结果是什么},{'id':5},{'id':6},{'id':7}]?
-
[ [{ }, { }], [{ }, { }], [{ }, { }], [{ }, { }] ]
-
["1","2","3","4","5","6","7"]是字符串数组,[{'id':1}]是 [[string:Int]] 数组 -
@NeerajSonaro 像这样:[[["id": 1], ["id": 2]], [["id": 3], ["id": 4]], [["id": 5], ["id": 6]], [["id": 7]]]?
-
那么我怎样才能达到这个结果..你能建议吗。