// // User.m // Juick // // Created by Vitaly on 01.02.14. // Copyright (c) 2014 com.juick. All rights reserved. // #import "User.h" @implementation User + (User *) fromJSON:(NSDictionary *)jsonData { User *user = [User new]; user.uid = jsonData[@"uid"]; user.uname = jsonData[@"uname"]; user.avatar = jsonData[@"avatar"]; user.token = jsonData[@"hash"]; user.unreadCount = [jsonData[@"messagesCount"] integerValue]; return user; } +(void) throwUnableToLogin:(UIViewController *)view error:(NSError *)error { UIAlertController *alert = [UIAlertController new]; NSString *title = error.userInfo[@"url"] ? error.userInfo[@"url"] : @"Something went wrong"; [alert setTitle:title]; [alert setMessage:error.localizedDescription]; [alert addAction:[UIAlertAction actionWithTitle:@"OK" style:UIAlertActionStyleCancel handler:nil]]; UIPopoverPresentationController *popover = [alert popoverPresentationController]; if (popover) { popover.sourceView = view.view; popover.sourceRect = CGRectMake(CGRectGetMidX(view.view.bounds), CGRectGetMidY(view.view.bounds), 0, 0); popover.permittedArrowDirections = UIPopoverArrowDirectionDown; } [view presentViewController:alert animated:YES completion:nil]; } @end