Skip to content

Instantly share code, notes, and snippets.

@ritch
Last active December 31, 2015 23:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ritch/8060602 to your computer and use it in GitHub Desktop.
Save ritch/8060602 to your computer and use it in GitHub Desktop.
LoopBack LBUser in iOS
// UserRepository and User do not exist in the sdk
UserRepository repository = adapter.createRepository(UserRepository.class);
HashMap attributes = new HashMap<String, Object>();
attributes.put("email", "me@domain.com");
attributes.put("password", "secret");
User me = repository.createModel(attributes);
me.save(new Model.Callback() {
@Override
public void onSuccess() {
// Pencil now exists on the server!
}
@Override
public void onError(Throwable t) {
// save failed, handle the error
}
})
User.create({
email: 'me@domain.com', // required by default
password: 'secret' // required by default
}, function (err, user) {
console.log(user.id); // => the user id (default type: db specific | number)
console.log(user.email); // => the user's email
});
LBRESTAdapter *adapter = [[UIApplication sharedApplication] delegate].adapter;
LBModelRepository *user = [adapter repositoryWithModelName:@"users"];
LBModel *me = [user modelWithDictionary:@{ "email": "me@domain.com", "password": "secret" }];
[me saveWithSuccess:^{
// user now exists on the server!
}
failure:^(NSError *error) {
NSLog("An error occurred: %@", error);
}];
@bajtos
Copy link

bajtos commented Dec 22, 2013

In the Java version, you can use ModelRepository and Model in the same way you did it in the iOS version. See ModelTest.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment