我是初学者,从解析中检索数组时遇到问题。 我的问题如下..
我创建了一个名为“TypeOfNumbers”的课程
var typeOfNumbers:PFObject = PFObject(className: "TypeOfNumbers")
typeOfNumbers["type"] = "Prime"
typeOfNumbers["numbers"] = ["2", "3", "5", "7", "11", "13"]
typeOfNumbers.saveInBackground()
现在假设我们在“TypeOfNumbers”类中有另一行,如下所示:
var typeOfNumbers:PFObject = PFObject(className: "TypeOfNumbers")
typeOfNumbers["type"] = "Squares
typeOfNumbers["numbers"] = ["1", "4", "9", "16", "25"]
typeOfNumbers.saveInBackground()
现在我想要检索这两个数组及其对应的类型..
假设我想要检索这些数组,并希望保存在以下字典中:
[Prime:[“2”,“3”,“5”,“7”,“11”,“13”],正方形:[“2”,“3”,“5”,“7” ,“11”,“13”]]
答案 0 :(得分:0)
您可以尝试编写此代码:
var dictionary = [String:String]
var number = 0
let typeOfNumbersAsArrayOfStrings = typeOfNumbers["numbers"] as! [String]
let typeOfNumbersAsArrayOfStrings2 = typeOfNumbers["numbers"] as! [String]
for object in typeOfNumbersAsArrayOfStrings {
dictionary["\(object)"] = typeOfNumbersAsArrayOfStrings2[number]
++number
}