目前正在尝试保存对象以解析数据库,当我打印对象时,它们包含我想要在数组字段中的新数组但由于某种原因,它不会保存到表中这一段时间有任何想法吗?
数组需要为每个查询添加一个新的整数值,对应于每个查询," test"数组存档,但将每个对象保存到USER类似乎是一个问题
func taskAllocation(){
// var query = PFQuery(className: "Tasks")
var query = PFUser.query()
// let user = PFUser()
var posts:[PFUser] = []
query.whereKey("Year", equalTo: yearTextField.text.toInt())
query.whereKey("Class", equalTo: classTextField.text.toInt())
query.whereKey("Keystage", equalTo: keystageTextField.text.toInt())
// query.limit = 10
query.findObjectsInBackgroundWithBlock { (objects: [AnyObject]!, error: NSError!) -> Void in
if error != nil {
println(error)
} else {
if objects.isEmpty {
println("empty query")
}
else {
for object in objects as [PFUser] {
var test:[Int] = object["taskIDs"] as [Int]
test.append(self.getIndex)
println(test)
object.setValue(test, forKey: "taskIDs")
object["tasksCorrect"] = "hello"
posts.append(object)
}
println(posts)
PFUser.saveAllInBackground(posts)
}}}
答案 0 :(得分:0)
我假设您要将这些组件保存到“任务”类而不是您的User类。 PFUser Query仅适用于没有任务的“_User”类。
var tasks:PFObject = PFObject(className: "Tasks")
// Make sure in your parse data table you have the columns created as type String or Int
item["Year"] = yearTextField.text.toInt()
item["Keystage"] = keystageTextField.text.toInt()
item["Class"] = classTextField.text.toInt())
// Save the task to a user, make sure you create a Username column in your data table
item["Username"] = PFUser.currentUser().username
// save it
item.saveInBackgroundWithTarget(nil , selector: nil)
你的代码有点笨重,所以我假设你想做什么。拍摄任务类的屏幕截图可能会有所帮助。