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

时间:2016-04-18 16:05:17

标签: swift syncano

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

 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)
        }

    }
}

我需要一个额外的字段来引用用户ID。 这是我的班级:

class userextra : SCDataObject {

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

}

1 个答案:

答案 0 :(得分:2)

好几次尝试后我设法将此引用保存到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 user_profile: SCUserProfile {
var id = 0
var Name = ""
var Surename = ""

}

最重要的是app delegate中的注册类

SCUser.registerClassWithProfileClass(userextra.self)
SCUser.registerClassWithProfileClass(user_profile.self)