Last active
December 31, 2015 23:29
-
-
Save ritch/8060602 to your computer and use it in GitHub Desktop.
LoopBack LBUser in iOS
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// UserRepository and User do not exist in the sdk | |
UserRepository repository = adapter.createRepository(UserRepository.class); | |
HashMap attributes = new HashMap<String, Object>(); | |
attributes.put("email", "[email protected]"); | |
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 | |
} | |
}) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
User.create({ | |
email: '[email protected]', // 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 | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
LBRESTAdapter *adapter = [[UIApplication sharedApplication] delegate].adapter; | |
LBModelRepository *user = [adapter repositoryWithModelName:@"users"]; | |
LBModel *me = [user modelWithDictionary:@{ "email": "[email protected]", "password": "secret" }]; | |
[me saveWithSuccess:^{ | |
// user now exists on the server! | |
} | |
failure:^(NSError *error) { | |
NSLog("An error occurred: %@", error); | |
}]; | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In the Java version, you can use
ModelRepository
andModel
in the same way you did it in the iOS version. See ModelTest.