【问题标题】:Saving multiple PFObjects from an array at once一次从数组中保存多个 PFObject
【发布时间】:2015-04-12 18:47:18
【问题描述】:

我试图一次将多个对象从一个数组设置到 Parses 数据库中,尽管所发生的只是设置其中一个对象而不是所有对象。不知道哪里出错了,代码:

var user2 = [PFUser]() //array of PFUsers.

 let addRoomObject = PFObject(className: "Room")
                for user in user2 {
                    println(user) //prints two multiple objects
                    addRoomObject["user1"] = PFUser.currentUser()
                    addRoomObject["user2"] = user
                    addRoomObject.saveInBackgroundWithBlock({ (success: Bool!, error: NSError!) -> Void in
                    if success == true {
                        println("Added new users to room")
                        } 
                    })
                }

【问题讨论】:

    标签: arrays swift parse-platform


    【解决方案1】:

    你可以使用

    改为PFObject.saveAllInBackground(array, block: { (succeeded: Bool, error: NSError!) -> Void in // you code here })

    祝你好运

    【讨论】:

    • 谢谢,但是与我已经写过的内容有关,我将如何写它,array 中的内容到底是什么???
    • 还有PFObject' does not have a member named 'saveAllInBackground???
    • 这有点晚,但添加以供参考。 Array 是放置 PFObject 数组的位置。此外,PFObject.saveAll 应该是您要查找的内容。
    猜你喜欢
    • 1970-01-01
    • 2014-05-31
    • 1970-01-01
    • 2012-08-18
    • 2021-12-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多