swiftsyncano

How to get and add to Syncano reference to user_profile


as in the title I have problem how adds to syncano reference to user_profile, If someone could tell me a hint? So this is my code:

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

    }
}

And I need 1 extra field with reference to user id. This is my class:

class userextra : SCDataObject {

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

}


Solution

  • Ok after several attempts I managed to save this reference to Syncano. This is my code:

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

    and user_profile class:

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

    }

    Most important is register class in app delegate

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