2

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

}

Namedix
  • 39
  • 6

1 Answers1

2

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)
Namedix
  • 39
  • 6
  • Actually, SCUserProfile is already a subclass of SCDataObject. You cannot register two classes at the same time to be user_profile - only the last call will affect how app works (and will use the class from the last call). – Mariusz Wiśniewski Apr 18 '16 at 20:57