This file contains 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
dispatch_group_t group = dispatch_group_create(); | |
dispatch_group_enter(group); | |
[[[SMClient defaultClient] dataStore] createObject:anObject inSchema:@"schema" onSuccess:^(NSDictionary *object, NSString *schema){ | |
// Do something with object | |
dispatch_group_leave(group); | |
} onFailure:^(NSError *error, NSDictionary* object, NSString *schema){ | |
// Handle error | |
dispatch_group_leave(group); |
This file contains 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
#import "MOBAppDelegate.h" | |
#import "MOBLoginViewController.h" | |
#import "MOBTabBarController.h" | |
#import "MOBViewPhotoViewController.h" | |
#import "StackMobPush.h" | |
#import <FacebookSDK/FacebookSDK.h> | |
@implementation MOBAppDelegate | |
@synthesize client = _client; |
This file contains 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
// ... prepare objects for save | |
// ready for save | |
// create dispatch queue | |
dispatch_queue_t queue = dispatch_queue_create("queue", NULL); | |
// save object | |
[[SMClient defaultClient] coreDataStore] saveWithSuccessCallbackQueue:queue failureCallbackQueue:queue onSuccess:^{ | |
// Success block called on queue (separate thread) |
This file contains 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
// In the method where you make the StackMob call | |
WhateverAppDelegate * = (WhateverAppDelegate *)[[UIApplication sharedApplication] delegate]; | |
[[[self.appDelegate client] dataStore] performSomeTask:task onSuccess:successBlock onFailure:^(NSError *error) { | |
[self.appDelegate handleError:error]; | |
}]; | |
// Then, in your App Delegate file, create the handleError: method to handle all your StackMob errors without | |
// having to repeat code, which might look something like this: |
This file contains 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
-(void)uploadDataToServer{ | |
NSManagedObject *newManagedObject = [NSEntityDescription insertNewObjectForEntityForName:@"Apartment" inManagedObjectContext:self.managedObjectContext]; | |
NSData *imageData = UIImageJPEGRepresentation(self.uploadImageView.image, 0.4); | |
NSString *picData = [SMBinaryDataConversion stringForBinaryData:imageData name:@"apartment.jpg" contentType:@"image/jpg"]; | |
NSString* apartmentType = self.apartmentTypeControl.selectedSegmentIndex == 0 ? @"House" : @"Flat"; | |
This file contains 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
ApartmentCell* cell = [tableView dequeueReusableCellWithIdentifier:@"ApartmentCell" forIndexPath:indexPath]; | |
Apartment *apartment = [self.apartments objectAtIndex:indexPath.row]; | |
NSNumber* roomCount = [apartment valueForKey:@"roomCount"]; | |
NSString* roomCountText = [NSString stringWithFormat:@"%d Bed", [roomCount intValue]]; | |
NSNumber* price = [apartment valueForKey:@"price"]; | |
NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; | |
[numberFormatter setNumberStyle: NSNumberFormatterCurrencyStyle]; |
This file contains 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
-(void)getAllApartments | |
{ | |
MBProgressHUD *hud = [MBProgressHUD showHUDAddedTo:self.view animated:YES]; | |
hud.mode = MBProgressHUDModeIndeterminate; | |
hud.labelText = @"Loading..."; | |
NSFetchRequest *fetch = [[NSFetchRequest alloc] initWithEntityName:@"Apartment"]; | |
[self.managedObjectContext executeFetchRequest:fetch onSuccess:^(NSArray *results) { | |
self.apartments = results; |
This file contains 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
-(IBAction)logInPressed:(id)sender | |
{ | |
[self.client loginWithUsername:self.userTextField.text password:self.passwordTextField.text onSuccess:^(NSDictionary *results) { | |
if ([[[self appDelegate] client] isLoggedIn]) { | |
NSLog(@"Logged in"); | |
} | |
[self performSegueWithIdentifier:@"list" sender:self]; | |
This file contains 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
-(IBAction)signUpUserPressed:(id)sender | |
{ | |
User *newUser = [[User alloc] initIntoManagedObjectContext:self.managedObjectContext]; | |
[newUser setValue:self.userRegisterTextField.text forKey:[newUser primaryKeyField]]; | |
[newUser setPassword:self.passwordRegisterTextField.text]; | |
[self.managedObjectContext saveOnSuccess:^{ | |
[self.navigationController popViewControllerAnimated:YES]; | |
} onFailure:^(NSError *error) { |
This file contains 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
#import "AppDelegate.h" | |
#import "ADVTheme.h" | |
#import "StackMob.h" | |
#define PUBLIC_KEY @"YOUR_PUBLIC_KEY" | |
@implementation AppDelegate | |
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions | |
{ |
NewerOlder