Created
August 8, 2016 19:09
-
-
Save harveyslash/47d8096e17fe54e51cfae984b412028c to your computer and use it in GitHub Desktop.
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
NSData *data = [message dataUsingEncoding:NSUTF8StringEncoding]; | |
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil]; | |
NSLog(@"THIS IS IT %@", [json valueForKey:@"message_create"]); | |
id jsonBody = [json valueForKey:@"message_create"]; | |
if ([Chat fetchById:[jsonBody valueForKey:@"id"] withContext:self.managedObjectContext]==nil) { | |
NSLog(@"GOT NIL FROM SOCKET"); | |
Chat *chat = [Chat initWithContext:self.managedObjectContext]; | |
chat.id = [jsonBody valueForKey:@"id"]; | |
chat.body = [jsonBody valueForKey:@"body"]; | |
chat.user = [User fetchByID:[jsonBody valueForKey:@"user_id"] inContext:self.managedObjectContext]; | |
NSString *date = [jsonBody valueForKey:@"created_at"]; | |
chat.created_at = [TimeFormatter NSDateFromServerString:date]; | |
chat.group = [Group fetchByID:[jsonBody valueForKey:@"grp_id"] inContext:self.managedObjectContext]; | |
[self.managedObjectContext save:nil]; | |
} | |
NSLog(@"Saved"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment