ios - 在 PFUser 注册后创建一个 PFObject 和 PFRelation

标签 ios swift parse-platform pfuser pfrelation

在我的结构中,我想注册一个用户并直接为其分配一个组(多对多关系模型)

以下是我注册用户的方式。完成后,我不知道如何使用 PFRelation 关联 PFObject。

有什么想法吗?

// SIGN UP USER
var user = PFUser();
user.email = emailTextField.text;
user.username = emailTextField.text;
user.password = passwordTextField.text;

user.signUpInBackgroundWithBlock({ (succeeded: Bool, error: NSError?) -> Void in
    if error == nil {
        //Create a PFObject
        var group = CustomPFObject();
        group.name = "My First Group";
    }
});

最佳答案

你可以这样做:

user.signUpInBackgroundWithBlock({ (succeeded: Bool, error: NSError?) -> Void in
    if error == nil {

        //Create a PFObject

        var group = CustomPFObject();
        group.name = "My First Group";

        var relation: PFRelation = group.relationForKey("your_key")

        relation.addObject(user)

        group.save() // synchronous

        group.saveInBackgroundWithBlock { (Bool, NSError?) -> Void in

        }   // async
    }
});

关于ios - 在 PFUser 注册后创建一个 PFObject 和 PFRelation,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30727524/

相关文章:

iphone - Xcode 4 停止提供堆栈跟踪,发生了什么?

ios - 如何为 iOS 13 的 SF Symbols 设置权重?

ios - 尝试设置 PFUser 的个人资料图片时出现 fatal error

ios - 解析 SDK iOS 分析

ios - 使用 twitterkit 将图片发布到 Twitter

ios - 在 Swift 中的 UITableViewController 顶部添加一个 UIView

ios - 删除 HTML 关键字或标签并在 Swift 3 中转换为普通可读字符串

ios - 从 AppDelegate 内访问 NavigationController 指向的初始 View

ios - Swift 3.0 与 2.2 源代码不兼容……我必须重建我的应用程序吗?

ios - 将数百个 PFObject 保存到 Parse 云