Skip to content

Instantly share code, notes, and snippets.

@stevederico
Last active December 11, 2015 23:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevederico/4676452 to your computer and use it in GitHub Desktop.
Save stevederico/4676452 to your computer and use it in GitHub Desktop.
AFNetworking + AFIncrementalStore + SDScaffoldKit = Client/Server App

AFNetworking + AFIncrementalStore + SDScaffoldKit = Client/Server App

SDScaffoldKit with AFNetworking Template

These are the exact steps needed to take to create an syncing client-server app in 3 minutes. Watch this video for a complete demo. You will need to have CocoaPods Installed on your machine.

  1. Install CocoaPods
  2. Create New Project with AFNetworking Xcode Template
  3. Close current project. cd to PROJECTNAME directory then
  4. Run pod install
  5. Run open PROJECTNAME.xcworkspace
  6. Create ENTITYNAME in PROJECTNAME.xcdatamodeld file
  7. Run git commit -a -m "first commit"
  8. Run heroku create --buildpack git://github.com/mattt/heroku-buildpack-core-data.git
  9. Run git push heroku master
  10. Copy random-name-here.herokuapp.com url from terminal, set kAPIBaseURLString in PROJECTNAMEAPIClient.m to random-name-here.herokuapp.com url.
  11. Add SDScaffoldKit to project. Then add #import "SDScaffoldKit.h" to PROJECTNAME-Prefix.pch
  12. Create SDScaffoldIndexViewController instance and set it to the rootViewController of the main navigationController.
  13. App Delegate should look like this:
- (BOOL)application:(UIApplication *)applicationdidFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    NSURLCache *URLCache = [[NSURLCache alloc] initWithMemoryCapacity:8 * 1024 * 1024 diskCapacity:20 * 1024 * 1024 diskPath:nil];
    [NSURLCache setSharedURLCache:URLCache];
    
    [[AFNetworkActivityIndicatorManager sharedManager] setEnabled:YES];
    
    SDScaffoldIndexViewController *scaffoldViewController = [[SDScaffoldIndexViewController alloc] 
    initWithEntityName:@"ENTITYNAME" sortBy:@"PROPERTY" context:self.managedObjectContext];
    
    self.navigationController = [[UINavigationController alloc] initWithRootViewController:scaffoldViewController];
    
    self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    self.window.rootViewController = self.navigationController;
    [self.window makeKeyAndVisible];
    
    return YES;
}
  1. open http://kAPIBaseURLString/MODELNAMEs in your browser i.e. http://sleepy-eyrie-2619.herokuapp.com/runs
  2. Run Xcode applciation
  3. Follow @stevederico on twitter, tell me what you think. Thank @mattt for the wonderful AFNetworking & AFIncrementalStore.

Common Errors

  • Don't forget to change the build target from Pods. Click Pods next to the Stop button and change to PROJECTNAME, then build and Run. Bad Good

LEGEND

  • PROJECTNAME - Full name of the Project i.e. "RunnerLog"
  • ENTITYNAME - Core Data Model Entity Name i.e. "Run"
  • PROPERTY - An attribute of the new Entity i.e "summary"
  • random-name-here.herokuapp.com url - Heroku webserver url i.e. http://sleepy-eyrie-2619.herokuapp.com
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment