Search code examples
iphoneioscore-datastackmob

How to add a user object into events using stackmob


I am using stackmob for backend service. I create a new user using these codes:

User *newUser = [[User alloc] initIntoManagedObjectContext:self.managedObjectContext];
[newUser setValue:info.username forKey:[newUser primaryKeyField]];
[newUser setValue:info.email forKey:@"email"];
[newUser setPassword:info.password];
NSError *error = nil;
if ([self.managedObjectContext save:&error]) {
}

User logs in using these codes:

[self.client loginWithUsername:info.username password:info.password onSuccess:^(NSDictionary *result) {
    [userDefaults setBool:YES forKey:@"signedin"];
    NSLog(@"user signed in");
} onFailure:^(NSError *error) {
    NSLog(@"login error");
}];

Right now the Event has many users.

So, I want to [self.event addUsersObject:(User *)]. But how do i get current logging user, so I can add current user into this event.


Solution

  • I'm the platform evangelist for StackMob.

    I just created a project where I fetched the currently logged in user and add that object to a relationship. You can download and take a look at the code yourself.

    https://github.com/SidneyAllen/hollagram-ios

    Look inside the JustSayinViewController.m file for the appropriate code.