Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Aug 21st, 2012  |  syntax: None  |  size: 2.96 KB  |  hits: 22  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1.  
  2. - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
  3.     // Initialize RestKit
  4.         RKObjectManager* objectManager = [RKObjectManager objectManagerWithBaseURL:@"http://twitter.com"];
  5.    
  6.     // Enable automatic network activity indicator management
  7.     objectManager.client.requestQueue.showsNetworkActivityIndicatorWhenBusy = YES;
  8.    
  9.     // Initialize object store
  10.     #ifdef RESTKIT_GENERATE_SEED_DB
  11.         NSString *seedDatabaseName = nil;
  12.         NSString *databaseName = RKDefaultSeedDatabaseFileName;
  13.     #else
  14.         NSString *seedDatabaseName = RKDefaultSeedDatabaseFileName;
  15.         NSString *databaseName = @"RKTwitterData.sqlite";
  16.     #endif
  17.  
  18.     objectManager.objectStore = [RKManagedObjectStore objectStoreWithStoreFilename:databaseName usingSeedDatabaseName:seedDatabaseName managedObjectModel:nil delegate:self];
  19.    
  20.     /*!
  21.      Map to a target object class -- just as you would for a non-persistent class. The entity is resolved
  22.      for you using the Active Record pattern where the class name corresponds to the entity name within Core Data.
  23.      Twitter status objects will be mapped onto RKTStatus instances.
  24.      */
  25.     RKManagedObjectMapping* statusMapping = [RKManagedObjectMapping mappingForClass:[RKTStatus class]];
  26.     statusMapping.primaryKeyAttribute = @"statusID";
  27.     [statusMapping mapKeyPathsToAttributes:@"id", @"statusID",
  28.      @"created_at", @"createdAt",
  29.      @"text", @"text",
  30.      @"url", @"urlString",
  31.      @"in_reply_to_screen_name", @"inReplyToScreenName",
  32.      @"favorited", @"isFavorited",
  33.      nil];
  34.    
  35.     // Register our mappings with the provider
  36.     [objectManager.mappingProvider setMapping:statusMapping forKeyPath:@"status"];
  37.  
  38. #ifdef RESTKIT_GENERATE_SEED_DB
  39.     RKLogConfigureByName("RestKit/ObjectMapping", RKLogLevelInfo);
  40.     RKLogConfigureByName("RestKit/CoreData", RKLogLevelTrace);
  41.     RKManagedObjectSeeder* seeder = [RKManagedObjectSeeder objectSeederWithObjectManager:objectManager];
  42.    
  43.     // Seed the database with instances of RKTStatus from a snapshot of the RestKit Twitter timeline
  44.     [seeder seedObjectsFromFile:@"restkit.json" withObjectMapping:statusMapping];
  45.    
  46.     // Finalize the seeding operation and output a helpful informational message
  47.     [seeder finalizeSeedingAndExit];
  48.    
  49.     // NOTE: If all of your mapped objects use keyPath -> objectMapping registration, you can perform seeding in one line of code:
  50.     // [RKManagedObjectSeeder generateSeedDatabaseWithObjectManager:objectManager fromFiles:@"users.json", nil];
  51. #endif
  52.    
  53.     // Create Window and View Controllers
  54.         RKTwitterViewController* viewController = [[[RKTwitterViewController alloc] initWithNibName:nil bundle:nil] autorelease];
  55.         UINavigationController* controller = [[UINavigationController alloc] initWithRootViewController:viewController];
  56.         UIWindow* window = [[UIWindow alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
  57.     [window addSubview:controller.view];
  58.     [window makeKeyAndVisible];
  59.  
  60.     return YES;
  61. }