如何获取并添加到 user_profile 的 Syncano 引用

How to get and add to Syncano reference to user_profile

如标题所示,我有问题如何添加到 user_profile 的 syncano 引用, 如果有人可以告诉我一个提示? 所以这是我的代码:

 func saveName() {
   let Uerextra = userextra()
    Uerextra.name = (self.dict.objectForKey("first_name") as? String)!
    Uerextra.lastName = (self.dict.objectForKey("last_name") as? String)!
    Uerextra.avatarUrl = self.dict.objectForKey("picture")?.objectForKey("data")?.objectForKey("url") as! String
    Uerextra.FacebookId = (self.dict.objectForKey("id") as? String)!
    Uerextra.saveWithCompletionBlock { error in
        if error != nil {
            print(error)
        }

    }
}

而且我需要 1 个额外的字段来参考用户 ID。 这是我的 class:

class userextra : SCDataObject {

var name = ""
var lastName = ""
var avatarUrl = ""
var FacebookId = ""
var user: SCUserProfile! = nil

}

好的,经过几次尝试,我设法保存了对 Syncano 的引用。 这是我的代码:

func saveName() {
    user_profile.please().enumaratePagesWithPredicate(nil, parameters: [SCPleaseParameterPageSize : 25]) {shouldStop, s_data, error in
        guard error == nil else {
            return
        }
        if let s_data = s_data as? [user_profile] {
            for user in s_data {
            let uzytkownik = user
            let Uerextra = userextra()
            Uerextra.name = (self.dict.objectForKey("first_name") as? String)!
            Uerextra.lastName = (self.dict.objectForKey("last_name") as? String)!
            Uerextra.avatarUrl = self.dict.objectForKey("picture")?.objectForKey("data")?.objectForKey("url") as! String
            Uerextra.FacebookId = (self.dict.objectForKey("id") as? String)!
            Uerextra.user = uzytkownik
                Uerextra.saveWithCompletionBlock { error in
                    if error != nil {
                        print(error)
                    }

                }
            }
        }

    }
}

和user_profile class:

class user_profile: SCUserProfile {
var id = 0
var Name = ""
var Surename = ""

}

最重要的是在 app delegate

中注册 class
SCUser.registerClassWithProfileClass(userextra.self)
SCUser.registerClassWithProfileClass(user_profile.self)