From 535375ae79dc914c6f9d1da2d62eb594e6fb88bd Mon Sep 17 00:00:00 2001 From: Mattt Thompson Date: Tue, 30 Oct 2012 14:16:35 -0700 Subject: [PATCH] Initial Commit --- LICENSE | 19 ++ .../TemplateInfo.plist | 224 ++++++++++++++++++ .../.xccurrentversion | 5 + .../contents | 4 + ...CKAGENAMEASIDENTIFIER___IncrementalStore.h | 6 + ...CKAGENAMEASIDENTIFIER___IncrementalStore.m | 22 ++ .../TemplateInfo.plist | 93 ++++++++ .../Application.xctemplate/TemplateInfo.plist | 86 +++++++ .../Application.xctemplate/gitignore | 13 + .../Application.xctemplate/gitkeep | 0 .../CocoaPods.xctemplate/TemplateInfo.plist | 31 +++ README.md | 33 +++ 12 files changed, 536 insertions(+) create mode 100644 LICENSE create mode 100644 Project Templates/AFNetworking/AFIncrementalStore.xctemplate/TemplateInfo.plist create mode 100644 Project Templates/AFNetworking/AFIncrementalStore.xctemplate/___PACKAGENAMEASIDENTIFIER___.xcdatamodeld/.xccurrentversion create mode 100644 Project Templates/AFNetworking/AFIncrementalStore.xctemplate/___PACKAGENAMEASIDENTIFIER___.xcdatamodeld/___PACKAGENAMEASIDENTIFIER___.xcdatamodel/contents create mode 100644 Project Templates/AFNetworking/AFIncrementalStore.xctemplate/___PACKAGENAMEASIDENTIFIER___IncrementalStore.h create mode 100644 Project Templates/AFNetworking/AFIncrementalStore.xctemplate/___PACKAGENAMEASIDENTIFIER___IncrementalStore.m create mode 100755 Project Templates/AFNetworking/AFNetworking.xctemplate/TemplateInfo.plist create mode 100755 Project Templates/AFNetworking/Application.xctemplate/TemplateInfo.plist create mode 100755 Project Templates/AFNetworking/Application.xctemplate/gitignore create mode 100644 Project Templates/AFNetworking/Application.xctemplate/gitkeep create mode 100755 Project Templates/AFNetworking/CocoaPods.xctemplate/TemplateInfo.plist create mode 100644 README.md diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..50a6f31 --- /dev/null +++ b/LICENSE @@ -0,0 +1,19 @@ +Copyright (c) 2012 Mattt Thompson (http://mattt.me/) + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in +all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN +THE SOFTWARE. diff --git a/Project Templates/AFNetworking/AFIncrementalStore.xctemplate/TemplateInfo.plist b/Project Templates/AFNetworking/AFIncrementalStore.xctemplate/TemplateInfo.plist new file mode 100644 index 0000000..a916b67 --- /dev/null +++ b/Project Templates/AFNetworking/AFIncrementalStore.xctemplate/TemplateInfo.plist @@ -0,0 +1,224 @@ + + + + + Identifier + com.afnetworking.template.project.AFIncrementalStore + Ancestors + + com.apple.dt.unit.cocoaTouchApplication + + Kind + Xcode.Xcode3.ProjectTemplateUnitKind + Options + + + Default + false + Description + Whether the application should use the Core Data framework for storage + Identifier + coreData + Name + Use Core Data + SortOrder + 1 + Type + checkbox + Units + + true + + Definitions + + ../Podfile:afincrementalstore + pod "AFIncrementalStore" + + ___PACKAGENAME___-Prefix.pch:objC:importCoreData + #import <CoreData/CoreData.h> + + ___PACKAGENAMEASIDENTIFIER___.xcdatamodeld + + Path + ___PACKAGENAMEASIDENTIFIER___.xcdatamodeld + Group + Models + + + ___VARIABLE_classPrefix:identifier___AppDelegate.h:methods:coreData + @property (readonly, strong, nonatomic) NSManagedObjectContext *managedObjectContext; +@property (readonly, strong, nonatomic) NSManagedObjectModel *managedObjectModel; +@property (readonly, strong, nonatomic) NSPersistentStoreCoordinator *persistentStoreCoordinator; + +- (void)saveContext; + + ___VARIABLE_classPrefix:identifier___AppDelegate.m:applicationWillTerminate:comments + // Saves changes in the application's managed object context before the application terminates. + + ___VARIABLE_classPrefix:identifier___AppDelegate.m:applicationWillTerminate:save + [self saveContext]; + + ___VARIABLE_classPrefix:identifier___AppDelegate.m:coreData + #pragma mark - Core Data + +- (void)saveContext { + NSError *error = nil; + NSManagedObjectContext *managedObjectContext = self.managedObjectContext; + if (managedObjectContext) { + if ([managedObjectContext hasChanges] && ![managedObjectContext save:&error]) { + NSLog(@"Unresolved error %@, %@", error, [error userInfo]); + abort(); + } + } +} + +- (NSManagedObjectContext *)managedObjectContext { + if (_managedObjectContext) { + return _managedObjectContext; + } + + NSPersistentStoreCoordinator *coordinator = [self persistentStoreCoordinator]; + if (coordinator) { + _managedObjectContext = [[NSManagedObjectContext alloc] initWithConcurrencyType:NSMainQueueConcurrencyType]; + [_managedObjectContext setPersistentStoreCoordinator:coordinator]; + } + + return _managedObjectContext; +} + +- (NSManagedObjectModel *)managedObjectModel { + if (_managedObjectModel) { + return _managedObjectModel; + } + + NSURL *modelURL = [[NSBundle mainBundle] URLForResource:@"___PACKAGENAMEASIDENTIFIER___" withExtension:@"momd"]; + _managedObjectModel = [[NSManagedObjectModel alloc] initWithContentsOfURL:modelURL]; + + return _managedObjectModel; +} + +- (NSPersistentStoreCoordinator *)persistentStoreCoordinator { + if (_persistentStoreCoordinator) { + return _persistentStoreCoordinator; + } + + _persistentStoreCoordinator = [[NSPersistentStoreCoordinator alloc] initWithManagedObjectModel:[self managedObjectModel]]; + + AFIncrementalStore *incrementalStore = (AFIncrementalStore *)[_persistentStoreCoordinator addPersistentStoreWithType:[___PACKAGENAMEASIDENTIFIER___IncrementalStore type] configuration:nil URL:nil options:nil error:nil]; + + NSURL *applicationDocumentsDirectory = [[[NSFileManager defaultManager] URLsForDirectory:NSDocumentDirectory inDomains:NSUserDomainMask] lastObject]; + NSURL *storeURL = [applicationDocumentsDirectory URLByAppendingPathComponent:@"___PACKAGENAMEASIDENTIFIER___.sqlite"]; + + NSDictionary *options = @{ + NSInferMappingModelAutomaticallyOption : @(YES), + NSMigratePersistentStoresAutomaticallyOption: @(YES) + }; + + NSError *error = nil; + if (![incrementalStore.backingPersistentStoreCoordinator addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:storeURL options:options error:&error]) { + NSLog(@"Unresolved error %@, %@", error, [error userInfo]); + abort(); + } + + return _persistentStoreCoordinator; +} + + + Classes/___PACKAGENAMEASIDENTIFIER___APIClient.h + + Beginning + #import "AFIncrementalStore.h" +#import "AFRestClient.h" + +@interface ___PACKAGENAMEASIDENTIFIER___APIClient : AFRESTClient <AFIncrementalStoreHTTPClient> + ++ (___PACKAGENAMEASIDENTIFIER___APIClient *)sharedClient; + + End + @end + Group + Networking + + + Classes/___PACKAGENAMEASIDENTIFIER___APIClient.m:AFIncrementalStore + #pragma mark - AFIncrementalStore + +- (id)representationOrArrayOfRepresentationsFromResponseObject:(id)responseObject { + return responseObject; +} + +- (NSDictionary *)attributesForRepresentation:(NSDictionary *)representation + ofEntity:(NSEntityDescription *)entity + fromResponse:(NSHTTPURLResponse *)response +{ + NSMutableDictionary *mutablePropertyValues = [[super attributesForRepresentation:representation ofEntity:entity fromResponse:response] mutableCopy]; + + // Customize the response object to fit the expected attribute keys and values + + return mutablePropertyValues; +} + +- (BOOL)shouldFetchRemoteAttributeValuesForObjectWithID:(NSManagedObjectID *)objectID + inManagedObjectContext:(NSManagedObjectContext *)context +{ + return NO; +} + +- (BOOL)shouldFetchRemoteValuesForRelationship:(NSRelationshipDescription *)relationship + forObjectWithID:(NSManagedObjectID *)objectID + inManagedObjectContext:(NSManagedObjectContext *)context +{ + return NO; +} + + + Classes/___PACKAGENAMEASIDENTIFIER___IncrementalStore.h + + Path + ___PACKAGENAMEASIDENTIFIER___IncrementalStore.h + Group + Networking + + + Classes/___PACKAGENAMEASIDENTIFIER___IncrementalStore.m + + Path + ___PACKAGENAMEASIDENTIFIER___IncrementalStore.m + Group + Networking + + + Nodes + + ../Podfile:afincrementalstore + ___PACKAGENAMEASIDENTIFIER___.xcdatamodeld + ___VARIABLE_classPrefix:identifier___AppDelegate.h:methods:coreData + ___VARIABLE_classPrefix:identifier___AppDelegate.h:import:___PACKAGENAMEASIDENTIFIER___IncrementalStore.h + ___VARIABLE_classPrefix:identifier___AppDelegate.m:implementation:synthesize:managedObjectContext = _managedObjectContext + ___VARIABLE_classPrefix:identifier___AppDelegate.m:implementation:synthesize:managedObjectModel = _managedObjectModel + ___VARIABLE_classPrefix:identifier___AppDelegate.m:implementation:synthesize:persistentStoreCoordinator = _persistentStoreCoordinator + ___VARIABLE_classPrefix:identifier___AppDelegate.m:implementation:dealloc:_managedObjectContext + ___VARIABLE_classPrefix:identifier___AppDelegate.m:implementation:dealloc:_managedObjectModel + ___VARIABLE_classPrefix:identifier___AppDelegate.m:implementation:dealloc:_persistentStoreCoordinator + ___VARIABLE_classPrefix:identifier___AppDelegate.m:applicationWillTerminate:save + ___VARIABLE_classPrefix:identifier___AppDelegate.m:coreData + ___PACKAGENAME___-Prefix.pch:objC:importCoreData + Classes/___PACKAGENAMEASIDENTIFIER___APIClient.m:AFIncrementalStore + Classes/___PACKAGENAMEASIDENTIFIER___IncrementalStore.h + Classes/___PACKAGENAMEASIDENTIFIER___IncrementalStore.m + + Targets + + + Frameworks + + CoreData + + + + + + + + + diff --git a/Project Templates/AFNetworking/AFIncrementalStore.xctemplate/___PACKAGENAMEASIDENTIFIER___.xcdatamodeld/.xccurrentversion b/Project Templates/AFNetworking/AFIncrementalStore.xctemplate/___PACKAGENAMEASIDENTIFIER___.xcdatamodeld/.xccurrentversion new file mode 100644 index 0000000..0c67376 --- /dev/null +++ b/Project Templates/AFNetworking/AFIncrementalStore.xctemplate/___PACKAGENAMEASIDENTIFIER___.xcdatamodeld/.xccurrentversion @@ -0,0 +1,5 @@ + + + + + diff --git a/Project Templates/AFNetworking/AFIncrementalStore.xctemplate/___PACKAGENAMEASIDENTIFIER___.xcdatamodeld/___PACKAGENAMEASIDENTIFIER___.xcdatamodel/contents b/Project Templates/AFNetworking/AFIncrementalStore.xctemplate/___PACKAGENAMEASIDENTIFIER___.xcdatamodeld/___PACKAGENAMEASIDENTIFIER___.xcdatamodel/contents new file mode 100644 index 0000000..193f33c --- /dev/null +++ b/Project Templates/AFNetworking/AFIncrementalStore.xctemplate/___PACKAGENAMEASIDENTIFIER___.xcdatamodeld/___PACKAGENAMEASIDENTIFIER___.xcdatamodel/contents @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/Project Templates/AFNetworking/AFIncrementalStore.xctemplate/___PACKAGENAMEASIDENTIFIER___IncrementalStore.h b/Project Templates/AFNetworking/AFIncrementalStore.xctemplate/___PACKAGENAMEASIDENTIFIER___IncrementalStore.h new file mode 100644 index 0000000..67bfcf5 --- /dev/null +++ b/Project Templates/AFNetworking/AFIncrementalStore.xctemplate/___PACKAGENAMEASIDENTIFIER___IncrementalStore.h @@ -0,0 +1,6 @@ + +#import "AFIncrementalStore.h" + +@interface ___PACKAGENAMEASIDENTIFIER___IncrementalStore : AFIncrementalStore + +@end \ No newline at end of file diff --git a/Project Templates/AFNetworking/AFIncrementalStore.xctemplate/___PACKAGENAMEASIDENTIFIER___IncrementalStore.m b/Project Templates/AFNetworking/AFIncrementalStore.xctemplate/___PACKAGENAMEASIDENTIFIER___IncrementalStore.m new file mode 100644 index 0000000..bc73e1b --- /dev/null +++ b/Project Templates/AFNetworking/AFIncrementalStore.xctemplate/___PACKAGENAMEASIDENTIFIER___IncrementalStore.m @@ -0,0 +1,22 @@ +#import "___PACKAGENAMEASIDENTIFIER___IncrementalStore.h" +#import "___PACKAGENAMEASIDENTIFIER___APIClient.h" + +@implementation ___PACKAGENAMEASIDENTIFIER___IncrementalStore + ++ (void)initialize { + [NSPersistentStoreCoordinator registerStoreClass:self forStoreType:[self type]]; +} + ++ (NSString *)type { + return NSStringFromClass(self); +} + ++ (NSManagedObjectModel *)model { + return [[NSManagedObjectModel alloc] initWithContentsOfURL:[[NSBundle mainBundle] URLForResource:@"___PACKAGENAMEASIDENTIFIER___" withExtension:@"xcdatamodeld"]]; +} + +- (id )HTTPClient { + return [___PACKAGENAMEASIDENTIFIER___APIClient sharedClient]; +} + +@end \ No newline at end of file diff --git a/Project Templates/AFNetworking/AFNetworking.xctemplate/TemplateInfo.plist b/Project Templates/AFNetworking/AFNetworking.xctemplate/TemplateInfo.plist new file mode 100755 index 0000000..af0606f --- /dev/null +++ b/Project Templates/AFNetworking/AFNetworking.xctemplate/TemplateInfo.plist @@ -0,0 +1,93 @@ + + + + + Identifier + com.afnetworking.template.project.AFNetworking + Name + AFNetworking Dependency + Ancestors + + + Definitions + + ../Podfile:afnetworking + pod "AFNetworking" + + ___PACKAGENAME___-Prefix.pch:objC:importSystemConfiguration + #import <SystemConfiguration/SystemConfiguration.h> + ___PACKAGENAME___-Prefix.pch:objC:importCoreServices + #import <MobileCoreServices/MobileCoreServices.h> + + Classes/___PACKAGENAMEASIDENTIFIER___APIClient.h + + Beginning + #import "AFHTTPClient.h" + +@interface ___PACKAGENAMEASIDENTIFIER___APIClient : AFHTTPClient + ++ (___PACKAGENAMEASIDENTIFIER___APIClient *)sharedClient; + + End + @end + Group + Networking + + + Classes/___PACKAGENAMEASIDENTIFIER___APIClient.m + + Beginning + #import "___PACKAGENAMEASIDENTIFIER___APIClient.h" +#import "AFJSONRequestOperation.h" + +static NSString * const k___PACKAGENAMEASIDENTIFIER___APIBaseURLString = @"<# API Base URL #>"; + +@implementation ___PACKAGENAMEASIDENTIFIER___APIClient + ++ (___PACKAGENAMEASIDENTIFIER___APIClient *)sharedClient { + static ___PACKAGENAMEASIDENTIFIER___APIClient *_sharedClient = nil; + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + _sharedClient = [[self alloc] initWithBaseURL:[NSURL URLWithString:k___PACKAGENAMEASIDENTIFIER___APIBaseURLString]]; + }); + + return _sharedClient; +} + +- (id)initWithBaseURL:(NSURL *)url { + self = [super initWithBaseURL:url]; + if (!self) { + return nil; + } + + [self registerHTTPOperationClass:[AFJSONRequestOperation class]]; + [self setDefaultHeader:@"Accept" value:@"application/json"]; + + return self; +} + + End + @end + Group + Networking + + + Description + + Kind + Xcode.Xcode3.ProjectTemplateUnitKind + Nodes + + ../Podfile:afnetworking + ___PACKAGENAME___-Prefix.pch:objC:importSystemConfiguration + ___PACKAGENAME___-Prefix.pch:objC:importCoreServices + Classes/___PACKAGENAMEASIDENTIFIER___APIClient.h + Classes/___PACKAGENAMEASIDENTIFIER___APIClient.m + + Options + + + SortOrder + 1 + + diff --git a/Project Templates/AFNetworking/Application.xctemplate/TemplateInfo.plist b/Project Templates/AFNetworking/Application.xctemplate/TemplateInfo.plist new file mode 100755 index 0000000..06bb3a4 --- /dev/null +++ b/Project Templates/AFNetworking/Application.xctemplate/TemplateInfo.plist @@ -0,0 +1,86 @@ + + + + + Name + AFNetworking Application + Description + This template provides a starting point for an application using AFNetworking. It provides an AFHTTPClient subclass, as well as a Podfile and GitHub's Objective-C .gitignore file. When the Core Data option is enabled, the application is configured for AFIncrementalStore. + Identifier + com.afnetworking.template.project.ios + Kind + Xcode.Xcode3.ProjectTemplateUnitKind + Ancestors + + com.afnetworking.template.project.CocoaPods + com.afnetworking.template.project.AFNetworking + com.afnetworking.template.project.AFIncrementalStore + com.apple.dt.unit.objectiveCApplication + com.apple.dt.unit.iPhoneBase + com.apple.dt.unit.prefixable + + Concrete + + Definitions + + ../.gitignore + + Path + gitignore + + Classes/Models/.gitkeep + + Path + gitkeep + Group + Models + + Classes/Views/.gitkeep + + Path + gitkeep + Group + Views + + Classes/Controllers/.gitkeep + + Path + gitkeep + Group + Controllers + + ___VARIABLE_classPrefix:identifier___AppDelegate.m:applicationdidFinishLaunchingWithOptions + - (BOOL)application:(UIApplication *)application +didFinishLaunchingWithOptions:(NSDictionary *)launchOptions +{ + NSURLCache *URLCache = [[NSURLCache alloc] initWithMemoryCapacity:8 * 1024 * 1024 diskCapacity:20 * 1024 * 1024 diskPath:nil]; + [NSURLCache setSharedURLCache:URLCache]; + + [[AFNetworkActivityIndicatorManager sharedManager] setEnabled:YES]; + + UIViewController *viewController = [[UITableViewController alloc] initWithStyle:UITableViewStylePlain]; + self.navigationController = [[UINavigationController alloc] initWithRootViewController:viewController]; + + self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; + self.window.rootViewController = self.navigationController; + [self.window makeKeyAndVisible]; + + return YES; +} + + ___VARIABLE_classPrefix:identifier___AppDelegate.h:methods:navigationController + @property (strong, nonatomic) UINavigationController *navigationController; + + + Nodes + + ___VARIABLE_classPrefix:identifier___AppDelegate.h:methods:navigationController + ___VARIABLE_classPrefix:identifier___AppDelegate.m:import:AFNetworkActivityIndicatorManager.h + + Options + + + SortOrder + 1 + + diff --git a/Project Templates/AFNetworking/Application.xctemplate/gitignore b/Project Templates/AFNetworking/Application.xctemplate/gitignore new file mode 100755 index 0000000..3a280bd --- /dev/null +++ b/Project Templates/AFNetworking/Application.xctemplate/gitignore @@ -0,0 +1,13 @@ +.DS_Store +*.swp +*~.nib + +build/ +test-reports/ + +*.pbxuser +*.perspective +*.perspectivev3 +*.mode1v3 +*.mode2v3 +xcuserdata \ No newline at end of file diff --git a/Project Templates/AFNetworking/Application.xctemplate/gitkeep b/Project Templates/AFNetworking/Application.xctemplate/gitkeep new file mode 100644 index 0000000..e69de29 diff --git a/Project Templates/AFNetworking/CocoaPods.xctemplate/TemplateInfo.plist b/Project Templates/AFNetworking/CocoaPods.xctemplate/TemplateInfo.plist new file mode 100755 index 0000000..b36ef27 --- /dev/null +++ b/Project Templates/AFNetworking/CocoaPods.xctemplate/TemplateInfo.plist @@ -0,0 +1,31 @@ + + + + + Identifier + com.afnetworking.template.project.CocoaPods + Name + CocoaPods + Ancestors + + + Definitions + + ../Podfile:platform + platform :ios, "5.0" + + Description + AFNetworking project template. + Kind + Xcode.Xcode3.ProjectTemplateUnitKind + Nodes + + ../Podfile:platform + + Options + + + SortOrder + 1 + + diff --git a/README.md b/README.md new file mode 100644 index 0000000..65e16df --- /dev/null +++ b/README.md @@ -0,0 +1,33 @@ +AFNetworking Xcode Project Templates +==================================== + +**Start Your Project Off Right, with CocoaPods & AFNetworking** + +This template provides a starting point for an application using [AFNetworking](https://github.com/afnetworking/afnetworking). It provides an `AFHTTPClient` subclass, as well as a [`Podfile`](http://cocoapods.org) and [GitHub's Objective-C .gitignore](https://github.com/github/gitignore/blob/master/Objective-C.gitignore) file. When the Core Data option is enabled, the application is configured for [AFIncrementalStore](https://github.com/AFNetworking/AFIncrementalStore). + +## Installation + +1. [Download](https://github.com/AFNetworking/Xcode-Project-Templates/zipball/master) or clone the repository +2. Move the contents of `Project Templates` in the repository into the `/Library/Developer/Xcode/Templates/Application/Project Templates` directory. +3. In Xcode, check that installation was successful by creating a New Project (⌘⇧N), and checking for the AFNetworking section under iOS. + +![Xcode Project Template Screenshot 1](https://raw.github.com/AFNetworking/Xcode-Project-Templates/screenshots/afnetworking-xcode-template-1.png) + +![Xcode Project Template Screenshot 2](https://raw.github.com/AFNetworking/Xcode-Project-Templates/screenshots/afnetworking-xcode-template-2.png) + +![Xcode Project Template Screenshot 3](https://raw.github.com/AFNetworking/Xcode-Project-Templates/screenshots/afnetworking-xcode-template-3.png) + +> Immediately after you've created your project, you should close the project window, and run `pod install` in the project directory. The installation process will generate an Xcode Workspace (.xcworkspace) file containing your original project and a project for the CocoaPods static library; you should use this exclusively from that point forward. + +## Contact + +Follow AFNetworking on Twitter ([@AFNetworking](https://twitter.com/AFNetworking)) + +### Creators + +[Mattt Thompson](http://github.com/mattt) +[@mattt](https://twitter.com/mattt) + +## License + +AFNetworking Xcode Project Templates are available under the MIT license. See the LICENSE file for more info.