├── .gitignore ├── CoreDeserializer.h ├── CoreDeserializer.m ├── CoreManager.h ├── CoreManager.m ├── CoreRequest.h ├── CoreRequest.m ├── CoreResource.h ├── CoreResource.m ├── CoreResult.h ├── CoreResult.m ├── CoreResultsController.h ├── CoreResultsController.m ├── CoreTableController.h ├── CoreTableController.m ├── CoreUtils.h ├── CoreUtils.m ├── Examples ├── BasecampClient │ ├── BasecampClient-Info.plist │ ├── BasecampClient.xcodeproj │ │ ├── mikelaurence.mode1v3 │ │ ├── mikelaurence.pbxuser │ │ └── project.pbxproj │ ├── BasecampClient_Prefix.pch │ ├── Classes │ │ ├── BasecampClientAppDelegate.h │ │ ├── BasecampClientAppDelegate.m │ │ ├── BasecampResource.h │ │ └── BasecampResource.m │ ├── Icon.png │ ├── MainWindow.xib │ ├── SecondView.xib │ ├── basecamp.xcdatamodel │ │ ├── elements │ │ └── layout │ └── main.m ├── CorePing │ ├── Classes │ │ ├── CorePingAppDelegate.h │ │ ├── CorePingAppDelegate.m │ │ ├── Ping.h │ │ ├── Ping.m │ │ ├── PingsController.h │ │ └── PingsController.m │ ├── CorePing-Info.plist │ ├── CorePing.xcodeproj │ │ ├── mikelaurence.mode1v3 │ │ ├── mikelaurence.pbxuser │ │ └── project.pbxproj │ ├── CorePing_Prefix.pch │ ├── MainWindow.xib │ ├── coreping.xcdatamodel │ │ ├── elements │ │ └── layout │ └── main.m ├── CorePingPlus │ ├── Classes │ │ ├── CorePingPlusAppDelegate.h │ │ ├── CorePingPlusAppDelegate.m │ │ ├── Ping.h │ │ ├── Ping.m │ │ ├── PingController.h │ │ ├── PingController.m │ │ ├── PingController.xib │ │ ├── PingsController.h │ │ └── PingsController.m │ ├── CorePingPlus-Info.plist │ ├── CorePingPlus.xcodeproj │ │ ├── mikelaurence.mode1v3 │ │ ├── mikelaurence.pbxuser │ │ └── project.pbxproj │ ├── CorePingPlus_Prefix.pch │ ├── MainWindow.xib │ ├── corepingplus.xcdatamodel │ │ ├── elements │ │ └── layout │ └── main.m ├── CoreTest │ ├── ArtistCollectionController.xib │ ├── Classes │ │ ├── Artist.h │ │ ├── Artist.m │ │ ├── ArtistCollectionController.h │ │ ├── ArtistCollectionController.m │ │ ├── CoreTestAppDelegate.h │ │ ├── CoreTestAppDelegate.m │ │ ├── Song.h │ │ ├── Song.m │ │ ├── User.h │ │ └── User.m │ ├── CoreResourceConfigurationTests.m │ ├── CoreResourceCoreDataTests.m │ ├── CoreResourceCreateTests.m │ ├── CoreResourceDestroyTests.m │ ├── CoreResourceReadTests.m │ ├── CoreResourceResultsTests.m │ ├── CoreResourceSerializationTests.m │ ├── CoreResourceTestCase.h │ ├── CoreResourceTestCase.m │ ├── CoreResourceUpdateTests.m │ ├── CoreTest-Info.plist │ ├── CoreTest.xcdatamodel │ │ ├── elements │ │ └── layout │ ├── CoreTest.xcodeproj │ │ ├── mikelaurence.mode1v3 │ │ ├── mikelaurence.pbxuser │ │ └── project.pbxproj │ ├── CoreUtilsTests.m │ ├── GHLogicTests_Prefix.pch │ ├── GHUnit │ │ ├── GHAsyncTestCase.h │ │ ├── GHTest.h │ │ ├── GHTestCase.h │ │ ├── GHTestGroup.h │ │ ├── GHTestMacros.h │ │ ├── GHTestRunner.h │ │ ├── GHTestSuite.h │ │ ├── GHTesting.h │ │ ├── GHUNSObject+Swizzle.h │ │ ├── GHUnit.h │ │ ├── GHUnitIPhoneAppDelegate.h │ │ ├── GHUnitIPhoneTestMain.m │ │ ├── Makefile │ │ ├── NSException+GHTestFailureExceptions.h │ │ ├── NSValue+GHValueFormatter.h │ │ ├── RunTests.sh │ │ └── libGHUnitIPhone3_0.a │ ├── MainWindow.xib │ ├── MiscBenchmarks.m │ ├── NSArrayCategoryTests.m │ ├── RunTests.sh │ ├── TestHelpers.h │ ├── TestHelpers.m │ ├── TestScript.sh │ ├── artists.0.alternate-field-names.json │ ├── artists.0.json │ ├── artists.0.update.json │ ├── artists.1.json │ ├── artists.2.json │ ├── artists.json │ └── main.m ├── LighthouseClient │ ├── Classes │ │ ├── LighthouseClientAppDelegate.h │ │ ├── LighthouseClientAppDelegate.m │ │ ├── LighthouseResource.h │ │ ├── LighthouseResource.m │ │ ├── Ticket.h │ │ ├── Ticket.m │ │ ├── TicketController.h │ │ ├── TicketController.m │ │ ├── TicketController.xib │ │ ├── TicketsController.h │ │ └── TicketsController.m │ ├── Icon.png │ ├── LighthouseClient-Info.plist │ ├── LighthouseClient.xcodeproj │ │ ├── mikelaurence.mode1v3 │ │ ├── mikelaurence.pbxuser │ │ └── project.pbxproj │ ├── LighthouseClient_Prefix.pch │ ├── MainWindow.xib │ ├── Resources-iPad │ │ └── MainWindow-iPad.xib │ ├── SecondView.xib │ ├── images │ │ └── icon-tickets.png │ ├── lighthouse.xcdatamodel │ │ ├── elements │ │ └── layout │ ├── main.m │ └── tickets.json └── TwitterClient │ ├── Classes │ ├── Status.h │ ├── Status.m │ ├── StatusesController.h │ ├── StatusesController.m │ ├── TwitterClientAppDelegate.h │ ├── TwitterClientAppDelegate.m │ ├── TwitterModel.h │ ├── TwitterModel.m │ ├── User.h │ └── User.m │ ├── MainWindow.xib │ ├── StatusesController.xib │ ├── TwitterClient-Info.plist │ ├── TwitterClient.xcodeproj │ ├── mikelaurence.mode1v3 │ ├── mikelaurence.pbxuser │ └── project.pbxproj │ ├── TwitterClient_Prefix.pch │ ├── main.m │ ├── twitter.xcdatamodel │ ├── elements │ └── layout │ └── users.mikelaurence.json ├── Libraries ├── ASIHTTPRequest │ ├── ASIAuthenticationDialog.h │ ├── ASIAuthenticationDialog.m │ ├── ASIFormDataRequest.h │ ├── ASIFormDataRequest.m │ ├── ASIHTTPRequest.h │ ├── ASIHTTPRequest.m │ ├── ASIHTTPRequestConfig.h │ ├── ASIInputStream.h │ ├── ASIInputStream.m │ ├── ASINSStringAdditions.h │ ├── ASINSStringAdditions.m │ ├── ASINetworkQueue.h │ └── ASINetworkQueue.m ├── DynamicCell │ ├── DynamicCell.h │ └── DynamicCell.m ├── JSON │ ├── JSON.h │ ├── NSObject+SBJSON.h │ ├── NSObject+SBJSON.m │ ├── NSString+SBJSON.h │ ├── NSString+SBJSON.m │ ├── SBJSON.h │ ├── SBJSON.m │ ├── SBJsonBase.h │ ├── SBJsonBase.m │ ├── SBJsonParser.h │ ├── SBJsonParser.m │ ├── SBJsonWriter.h │ └── SBJsonWriter.m ├── KissXML │ ├── DDXML.h │ ├── DDXMLDocument.h │ ├── DDXMLDocument.m │ ├── DDXMLElement.h │ ├── DDXMLElement.m │ ├── DDXMLElementAdditions.h │ ├── DDXMLElementAdditions.m │ ├── DDXMLNode.h │ ├── DDXMLNode.m │ ├── DDXMLPrivate.h │ ├── NSStringAdditions.h │ └── NSStringAdditions.m ├── NSDate-Helper │ ├── NSDate+Helper.h │ ├── NSDate+Helper.m │ └── README.textile └── Reachability │ ├── Reachability.h │ └── Reachability.m ├── NSArray+Core.h ├── NSArray+Core.m ├── NSMutableArray+Core.h ├── NSMutableArray+Core.m ├── NSObject+Core.h ├── NSObject+Core.m ├── NSSet+Core.h ├── NSSet+Core.m ├── NSString+InflectionSupport.h ├── NSString+InflectionSupport.m └── readme.md /.gitignore: -------------------------------------------------------------------------------- 1 | Examples/BasecampClient/build 2 | Examples/CoreTest/build 3 | Examples/CorePing/build 4 | Examples/CorePingPlus/build 5 | Examples/LighthouseClient/build 6 | Examples/TwitterClient/build -------------------------------------------------------------------------------- /CoreDeserializer.h: -------------------------------------------------------------------------------- 1 | // 2 | // CoreDeserializer.h 3 | // Core Resource 4 | // 5 | // Created by Mike Laurence on 3/11/10. 6 | // Copyright 2010 Mike Laurence. 7 | // 8 | 9 | #import 10 | #import "CoreManager.h" 11 | 12 | /** 13 | The job of CoreDeserializers is to transform serialized resource strings into 14 | CoreResource-formatted collections (nested arrays & dictionaries). They do pass 15 | actual resources to their targets at the time of completion, but the generation 16 | of said resources is handed off to individual CoreResource classes, where 17 | customized domain logic is better placed. This also allows for direct creates 18 | and updates using property dictionaries and such, much like in ActiveRecord 19 | where you can call #update_attributes with a hash. 20 | */ 21 | @interface CoreDeserializer : NSOperation { 22 | id source; 23 | NSString *sourceString; 24 | Class resourceClass; 25 | NSString *format; 26 | CoreManager *coreManager; 27 | NSManagedObjectContext *managedObjectContext; 28 | 29 | // Results 30 | NSError *error; 31 | id resources; 32 | 33 | // Target 34 | id target; 35 | SEL action; 36 | } 37 | 38 | @property (nonatomic, retain) id source; 39 | @property (nonatomic, readonly) NSString* sourceString; 40 | @property (nonatomic, assign) Class resourceClass; 41 | @property (nonatomic, retain) NSString* format; 42 | @property (nonatomic, retain) CoreManager *coreManager; 43 | 44 | @property (nonatomic, retain) id target; 45 | @property (nonatomic, assign) SEL action; 46 | 47 | - (id) initWithSource:(id)source andResourceClass:(Class)clazz; 48 | 49 | #pragma mark - 50 | #pragma mark Source 51 | - (NSString*) sourceString; 52 | 53 | #pragma mark - 54 | #pragma mark Format determination 55 | - (NSString*) formatFromHeader:(NSString*)header inDictionary:(SEL)dictionarySelector; 56 | - (NSString*) allowedFormatsFromString:(NSString*)string; 57 | 58 | #pragma mark - 59 | #pragma mark Deserialization 60 | 61 | /** 62 | Generates resources from a serialized string. 63 | Must be overriden in subclasses to accomodate different formats, etc. 64 | */ 65 | - (NSArray*) resourcesFromString:(NSString*)string; 66 | 67 | /** 68 | Generates resources from CoreResource-formatted data collections 69 | (basically just hands off generation to the root resource class, with a few specific options) 70 | */ 71 | - (NSArray*) resourcesFromData:(id)data; 72 | 73 | @end 74 | 75 | @interface CoreJSONDeserializer : CoreDeserializer 76 | - (id) resourcesFromJSONData:(id)jsonData; 77 | - (id) resourceDataFromJSONData:(id)jsonData; 78 | - (id) resourceDataFromJSONArray:(NSArray*)array; 79 | - (id) resourceDataFromJSONDictionary:(NSDictionary*)dict; 80 | @end 81 | 82 | #ifdef DDXMLDocument 83 | @interface CoreXMLDeserializer : CoreDeserializer 84 | @end 85 | #endif -------------------------------------------------------------------------------- /CoreManager.h: -------------------------------------------------------------------------------- 1 | // 2 | // CoreResource.h 3 | // CoreResource 4 | // 5 | // Created by Mike Laurence on 12/24/09. 6 | // Copyright Mike Laurence 2010. All rights reserved. 7 | // 8 | 9 | #import "ASIHTTPRequest.h" 10 | 11 | @interface CoreManager : NSObject { 12 | NSManagedObjectModel *managedObjectModel; 13 | NSManagedObjectContext *managedObjectContext; 14 | NSPersistentStoreCoordinator *persistentStoreCoordinator; 15 | 16 | NSOperationQueue *requestQueue; 17 | NSOperationQueue *deserialzationQueue; 18 | 19 | NSString *remoteSiteURL; 20 | 21 | // Default setting for whether or not to get data from within the bundle (instead of performing remote HTTP requests) 22 | BOOL useBundleRequests; 23 | 24 | // Artificial delay added for bundle requests 25 | float bundleRequestDelay; 26 | 27 | NSDateFormatter *defaultDateParser; 28 | 29 | NSMutableDictionary *entityDescriptions; 30 | NSMutableDictionary *modelProperties; 31 | NSMutableDictionary *modelRelationships; 32 | NSMutableDictionary *modelAttributes; 33 | 34 | int logLevel; 35 | } 36 | 37 | @property (nonatomic, retain, readonly) NSManagedObjectModel *managedObjectModel; 38 | @property (nonatomic, retain, readonly) NSManagedObjectContext *managedObjectContext; 39 | @property (nonatomic, retain, readonly) NSPersistentStoreCoordinator *persistentStoreCoordinator; 40 | 41 | @property (nonatomic, retain) NSOperationQueue *requestQueue; 42 | @property (nonatomic, retain) NSOperationQueue *deserialzationQueue; 43 | 44 | @property (nonatomic, retain) NSString *remoteSiteURL; 45 | @property (nonatomic, assign) BOOL useBundleRequests; 46 | @property (nonatomic, assign) float bundleRequestDelay; 47 | 48 | @property (nonatomic, retain) NSDateFormatter *defaultDateParser; 49 | 50 | @property (nonatomic, retain) NSMutableDictionary *entityDescriptions; 51 | @property (nonatomic, retain) NSMutableDictionary *modelProperties; 52 | @property (nonatomic, retain) NSMutableDictionary *modelRelationships; 53 | @property (nonatomic, retain) NSMutableDictionary *modelAttributes; 54 | 55 | @property (nonatomic, assign) int logLevel; 56 | 57 | + (CoreManager*) main; 58 | + (void) setMain: (CoreManager*)newMain; 59 | 60 | - (id) initWithOptions:(NSDictionary*)options; 61 | - (NSString*)applicationDocumentsDirectory; 62 | 63 | #pragma mark - 64 | #pragma mark Networking 65 | - (void) enqueueRequest:(ASIHTTPRequest*)request; 66 | 67 | #pragma mark - 68 | #pragma mark Alerts & Errors 69 | + (void) alertWithError:(NSError*)error; 70 | + (void) alertWithTitle:(NSString*)title andMessage:(NSString*)message; 71 | + (void) logCoreDataError:(NSError*)error; 72 | 73 | #pragma mark - 74 | #pragma mark Core Data 75 | - (void) save; 76 | 77 | /** 78 | Creates and returns a new NSManagedObjectContext pointing to the main persistent store 79 | */ 80 | - (NSManagedObjectContext*) newContext; 81 | 82 | - (void) mergeContext:(NSNotification*)notification; 83 | 84 | @end 85 | 86 | -------------------------------------------------------------------------------- /CoreRequest.h: -------------------------------------------------------------------------------- 1 | // 2 | // CoreRequest.h 3 | // CoreResource 4 | // 5 | // Created by Mike Laurence on 12/31/09. 6 | // Copyright 2009 Mike Laurence. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "ASIHTTPRequest.h" 11 | 12 | @interface CoreRequest : ASIHTTPRequest { 13 | id coreDelegate; 14 | SEL coreSelector; 15 | 16 | NSString* bundleDataPath; 17 | NSString* bundleDataResult; 18 | } 19 | 20 | @property (nonatomic, retain) id coreDelegate; 21 | @property (nonatomic, assign) SEL coreSelector; 22 | 23 | @property (nonatomic, retain) NSString* bundleDataPath; 24 | @property (nonatomic, retain) NSString* bundleDataResult; 25 | 26 | - (void) executeAsBundleRequest; 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /CoreRequest.m: -------------------------------------------------------------------------------- 1 | // 2 | // CoreRequest.m 3 | // CoreResource 4 | // 5 | // Created by Mike Laurence on 12/31/09. 6 | // Copyright 2009 Mike Laurence. All rights reserved. 7 | // 8 | 9 | #import "CoreRequest.h" 10 | #import "CoreManager.h" 11 | 12 | 13 | @implementation CoreRequest 14 | 15 | @synthesize coreDelegate, coreSelector; 16 | @synthesize bundleDataPath, bundleDataResult; 17 | 18 | - (void) executeAsBundleRequest { 19 | NSError* parseError = nil; 20 | self.bundleDataResult = [NSString stringWithContentsOfFile: 21 | [[NSBundle mainBundle] pathForResource:bundleDataPath ofType:@"json"] 22 | encoding:NSUTF8StringEncoding error:&parseError]; 23 | 24 | if (parseError == nil) { 25 | if (didFinishSelector && ![self isCancelled] && [delegate respondsToSelector:didFinishSelector]) { 26 | if ([CoreManager main].bundleRequestDelay == 0) 27 | [delegate performSelector:didFinishSelector withObject:self]; 28 | else { 29 | [delegate performSelector:didFinishSelector withObject:self afterDelay:[CoreManager main].bundleRequestDelay]; 30 | } 31 | } 32 | } 33 | else 34 | [self failWithError:parseError]; 35 | } 36 | 37 | - (NSString*) stringData { 38 | return bundleDataResult != nil ? bundleDataResult : [self responseString]; 39 | } 40 | 41 | - (NSString*) responseString { 42 | return bundleDataResult != nil ? bundleDataResult : [super responseString]; 43 | } 44 | 45 | - (void) dealloc { 46 | [bundleDataResult release]; 47 | [bundleDataPath release]; 48 | [super dealloc]; 49 | } 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /CoreResult.h: -------------------------------------------------------------------------------- 1 | // 2 | // CoreResult.h 3 | // CoreResource 4 | // 5 | // Created by Mike Laurence on 12/31/09. 6 | // Copyright 2009 Mike Laurence. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CoreRequest.h" 11 | 12 | @class CoreResource; 13 | 14 | @interface CoreResult : NSObject { 15 | id source; 16 | NSArray *resources; 17 | NSArray *resourceIds; 18 | NSError *error; 19 | 20 | NSManagedObjectContext *faultContext; 21 | } 22 | 23 | @property (nonatomic, retain, readonly) id source; 24 | @property (nonatomic, retain, readonly) NSArray* resources; 25 | @property (nonatomic, retain, readonly) NSError* error; 26 | 27 | @property (nonatomic, retain, readonly) NSManagedObjectContext *faultContext; 28 | 29 | - (id) initWithResources:(id)resources; 30 | - (id) initWithSource:(id)source andResources:(id)resources; 31 | - (id) initWithError:(NSError*)error; 32 | 33 | /* 34 | Returns a single resource (specifically, the first object in the resources array). 35 | This is a convenience method for when you know you'll only have one result or when you just don't care. 36 | */ 37 | - (CoreResource*) resource; 38 | 39 | - (BOOL) hasAnyResources; 40 | - (int) resourceCount; 41 | 42 | - (void) faultResourcesWithContext:(NSManagedObjectContext*)context; 43 | 44 | 45 | @end 46 | -------------------------------------------------------------------------------- /CoreResult.m: -------------------------------------------------------------------------------- 1 | // 2 | // CoreResult.m 3 | // CoreResource 4 | // 5 | // Created by Mike Laurence on 12/31/09. 6 | // Copyright 2009 Mike Laurence. All rights reserved. 7 | // 8 | 9 | #import "CoreResult.h" 10 | #import "CoreUtils.h" 11 | #import "CoreManager.h" 12 | #import "NSArray+Core.h" 13 | 14 | 15 | @implementation CoreResult 16 | 17 | @synthesize source; 18 | @synthesize resources; 19 | @synthesize error; 20 | @synthesize faultContext; 21 | 22 | - (id) initWithResources:(id)theResources { 23 | return [self initWithSource:nil andResources:theResources]; 24 | } 25 | 26 | - (id) initWithSource:(id)theSource andResources:(id)theResources { 27 | if (self = [super init]) { 28 | source = [theSource retain]; 29 | resources = [ToArray(theResources) retain]; 30 | } 31 | //NSLog(@"CoreResult: source: %@, theResources: %i, self.resources: %i", source, [theResources count], [self.resources count]); 32 | return self; 33 | } 34 | 35 | - (id) initWithError:(NSError*)theError { 36 | if (self = [super init]) { 37 | error = [theError retain]; 38 | } 39 | NSLog(@"CoreResult with error: %@", error); 40 | return self; 41 | } 42 | 43 | - (void) faultResourcesWithContext:(NSManagedObjectContext*)context { 44 | faultContext = [context retain]; 45 | 46 | // Set resourceIds array and release resources; when the resources are next requested, they 47 | // will be re-fetched from the fault context 48 | resourceIds = [[ToArray(resources) arrayMappedBySelector:@selector(objectID)] retain]; 49 | [resources release]; 50 | resources = nil; 51 | } 52 | 53 | - (CoreResource*) resource { 54 | return [self resources] != nil && [self resourceCount] > 0 ? [[self resources] objectAtIndex:0] : nil; 55 | } 56 | 57 | - (NSArray*) resources { 58 | if (resources == nil && resourceIds != nil && faultContext != nil) { 59 | resources = [[NSMutableArray arrayWithCapacity:[resourceIds count]] retain]; 60 | for (NSManagedObjectID *objId in resourceIds) 61 | [(NSMutableArray*)resources addObject:[faultContext objectWithID:objId]]; 62 | } 63 | 64 | return resources; 65 | } 66 | 67 | - (BOOL) hasAnyResources { 68 | return [self resourceCount] > 0; 69 | } 70 | 71 | - (int) resourceCount { 72 | return [self resources] != nil ? [[self resources] count] : 0; 73 | } 74 | 75 | 76 | 77 | #pragma mark - 78 | #pragma mark Fast enumeration 79 | 80 | - (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState*)state objects:(id*)stackbuf count:(NSUInteger)len { 81 | return [resources countByEnumeratingWithState:state objects:stackbuf count:len]; 82 | } 83 | 84 | 85 | 86 | #pragma mark - 87 | #pragma mark Lifecycle end 88 | 89 | - (void) dealloc { 90 | [source release]; 91 | [resources release]; 92 | [resourceIds release]; 93 | [error release]; 94 | [super dealloc]; 95 | } 96 | 97 | @end 98 | -------------------------------------------------------------------------------- /CoreResultsController.h: -------------------------------------------------------------------------------- 1 | // 2 | // CoreResultsController.h 3 | // CoreResource 4 | // 5 | // Created by Mike Laurence on 12/24/09. 6 | // Copyright Mike Laurence 2010. All rights reserved. 7 | // 8 | 9 | #if TARGET_OS_IPHONE 10 | 11 | #import "CoreRequest.h" 12 | 13 | @class CoreResource; 14 | 15 | @interface CoreResultsController : NSFetchedResultsController { 16 | Class entityClass; 17 | } 18 | 19 | @property (nonatomic) Class entityClass; 20 | 21 | - (void) fetch; 22 | - (void) fetchWithSort:(id)sort; 23 | - (void) fetch:(id)parameters; 24 | - (void) fetch:(id)parameters withSort:(id)sort; 25 | 26 | #pragma mark - 27 | #pragma mark Convenience fetch methods 28 | - (void) fetchForRelatedResource:(CoreResource*)resource withSort:(id)sort; 29 | - (void) fetchForRelatedResource:(CoreResource*)resource withParameters:(id)parameters andSort:(id)sort; 30 | - (void) fetchForResource:(CoreResource*)resource inRelationship:(NSString*)relationshipName withSort:(id)sort; 31 | - (void) fetchForResource:(CoreResource*)resource inRelationship:(NSString*)relationshipName withParameters:(id)parameters andSort:(id)sort; 32 | 33 | @end 34 | 35 | #endif -------------------------------------------------------------------------------- /CoreResultsController.m: -------------------------------------------------------------------------------- 1 | // 2 | // CoreResultsController.m 3 | // CoreResource 4 | // 5 | // Created by Mike Laurence on 12/24/09. 6 | // Copyright Mike Laurence 2010. All rights reserved. 7 | // 8 | 9 | #if TARGET_OS_IPHONE 10 | 11 | #import "CoreResultsController.h" 12 | #import "CoreUtils.h" 13 | #import "NSString+InflectionSupport.h" 14 | 15 | 16 | @implementation CoreResultsController 17 | 18 | @synthesize entityClass; 19 | 20 | - (void) fetch { 21 | [self fetch:nil]; 22 | } 23 | 24 | - (void) fetchWithSort:(id)sort { 25 | [self fetch:nil withSort:sort]; 26 | } 27 | 28 | - (void) fetch:(id)parameters { 29 | id sort = [CoreUtils sortDescriptorsFromParameters:parameters]; 30 | [self fetch:parameters withSort:sort]; 31 | } 32 | 33 | 34 | - (void) fetch:(id)parameters withSort:(id)sort { 35 | 36 | self.fetchRequest.predicate = [CoreUtils predicateFromObject:parameters]; 37 | [self.fetchRequest setSortDescriptors:[CoreUtils sortDescriptorsFromParameters:sort]]; 38 | 39 | NSError *error = nil; 40 | if (![self performFetch:&error]) { 41 | NSLog(@"[CoreResultsController#fetchLocal] Error on local core data fetch: %@", error); 42 | } 43 | } 44 | 45 | 46 | 47 | #pragma mark - 48 | #pragma mark Convenience fetch methods 49 | 50 | - (void) fetchForRelatedResource:(CoreResource*)resource withSort:(id)sort { 51 | [self fetchForRelatedResource:resource withParameters:nil andSort:sort]; 52 | } 53 | 54 | - (void) fetchForRelatedResource:(CoreResource*)resource withParameters:(id)parameters andSort:(id)sort { 55 | [self fetchForResource:resource 56 | inRelationship:[NSStringFromClass([resource class]) decapitalize] 57 | withParameters:parameters 58 | andSort:sort]; 59 | } 60 | 61 | - (void) fetchForResource:(CoreResource*)resource inRelationship:(NSString*)relationshipName withSort:(id)sort { 62 | [self fetchForResource:resource inRelationship:relationshipName withParameters:nil andSort:sort]; 63 | } 64 | 65 | - (void) fetchForResource:(CoreResource*)resource inRelationship:(NSString*)relationshipName withParameters:(id)parameters andSort:(id)sort { 66 | 67 | // Get relationship to related resource 68 | NSRelationshipDescription *relationship = [[entityClass performSelector:@selector(relationshipsByName)] objectForKey:relationshipName]; 69 | 70 | // Generate relationship predicate 71 | NSPredicate *relationshipPredicate = [relationship isToMany] ? 72 | [NSPredicate predicateWithFormat:@"%@ in %K", resource, relationshipName] : 73 | [NSPredicate predicateWithFormat:@"%K = %@", relationshipName, resource]; 74 | 75 | // Compound relationship predicate with parameters predicate if parameters are not nil; otherwise, just keep using relationship predicate 76 | NSPredicate *fetchPredicate = parameters != nil ? 77 | [NSCompoundPredicate andPredicateWithSubpredicates: 78 | [NSArray arrayWithObjects:relationshipPredicate, [CoreUtils predicateFromObject:parameters], nil]] : 79 | relationshipPredicate; 80 | 81 | // Perform fetch using parent to generate predicate 82 | [self fetch:fetchPredicate withSort:[CoreUtils sortDescriptorsFromString:sort]]; 83 | } 84 | 85 | 86 | 87 | #pragma mark - 88 | #pragma mark Lifecycle end 89 | 90 | - (void) dealloc { 91 | [super dealloc]; 92 | } 93 | 94 | @end 95 | 96 | #endif -------------------------------------------------------------------------------- /CoreTableController.h: -------------------------------------------------------------------------------- 1 | // 2 | // CoreTableController.h 3 | // CoreResource 4 | // 5 | // Created by Mike Laurence on 12/29/09. 6 | // Copyright Mike Laurence 2009. All rights reserved. 7 | // 8 | 9 | #if TARGET_OS_IPHONE 10 | 11 | #import "CoreResultsController.h" 12 | #import "CoreResource.h" 13 | 14 | 15 | @interface CoreTableController : UIViewController { 16 | CoreResultsController *coreResultsController; 17 | 18 | NSTimer *tableReloadTimer; 19 | NSNumber *tableReloadDelay; 20 | } 21 | 22 | @property (nonatomic, retain) CoreResultsController *coreResultsController; 23 | 24 | @property (nonatomic, retain) NSTimer *tableReloadTimer; 25 | @property (nonatomic, retain) NSNumber *tableReloadDelay; 26 | 27 | #pragma mark - 28 | #pragma mark Results methods 29 | - (Class) model; 30 | - (int) resultsSectionCount; 31 | - (BOOL) hasResults; 32 | - (id) resultsInfoForSection:(int)section; 33 | - (int) resultsCountForSection:(int)section; 34 | - (CoreResource*) resourceAtIndexPath:(NSIndexPath*)indexPath; 35 | - (NSString*) noResultsMessage; 36 | - (BOOL) hasNoResultsMessage; 37 | 38 | #pragma mark - 39 | #pragma mark Table view methods 40 | - (void) loadTableView; 41 | - (UITableView*) tableView; 42 | - (UITableViewCell*) tableView:(UITableView*)tableView resultCellForRowAtIndexPath:(NSIndexPath*)indexPath; 43 | - (UITableViewCell*) noResultsCellForTableView:(UITableView*)tableView; 44 | 45 | #pragma mark - 46 | #pragma mark Core Results Controller 47 | - (void) setSectionKeyPath:(NSString*)keyPath; 48 | - (CoreResultsController*) coreResultsControllerWithSectionKeyPath:(NSString*)keyPath; 49 | 50 | @end 51 | 52 | #endif -------------------------------------------------------------------------------- /CoreUtils.h: -------------------------------------------------------------------------------- 1 | // 2 | // CoreUtils.h 3 | // CoreResource 4 | // 5 | // Created by Mike Laurence on 12/24/09. 6 | // Copyright 2010 Mike Laurence. All rights reserved. 7 | // 8 | 9 | @interface CoreUtils : NSObject { 10 | } 11 | 12 | #pragma mark - 13 | #pragma mark Instantiation macros 14 | 15 | #define $D(...) [NSDictionary dictionaryWithObjectsAndKeys: __VA_ARGS__, nil] 16 | #define $A(...) [NSArray arrayWithObjects: __VA_ARGS__, nil] 17 | #define $S(format, ...) [NSString stringWithFormat:format, ## __VA_ARGS__] 18 | #define $I(i) [NSNumber numberWithInt:i] 19 | #define $F(f) [NSNumber numberWithFloat:f] 20 | #define $B(b) ((b) ? (id)kCFBooleanTrue : (id)kCFBooleanFalse) 21 | 22 | #pragma mark - 23 | #pragma mark Misc macros 24 | #define ToArray(object) (object != nil ? ([object isKindOfClass:[NSArray class]] ? object : [NSArray arrayWithObject:object]) : [NSArray array]) 25 | #define Log(format, ...) NSLog(@"%s:%@", __PRETTY_FUNCTION__, [NSString stringWithFormat:format, ## __VA_ARGS__]); 26 | #define StartTimer NSTimeInterval start = [NSDate timeIntervalSinceReferenceDate]; 27 | #define EndTimer(msg) NSTimeInterval stop = [NSDate timeIntervalSinceReferenceDate]; Log([NSString stringWithFormat:@"%@ Time = %f", msg, stop-start]); 28 | 29 | #pragma mark - 30 | #pragma mark Global stopwatch 31 | + (void) resetStopwatch; 32 | + (NSTimeInterval) stopwatchTime; 33 | #define ResetStopwatch [CoreUtils resetStopwatch]; 34 | #define LogStopwatch(msg) Log($S(@"%@ Stopwatch = %f", msg, [CoreUtils stopwatchTime])); 35 | 36 | 37 | #pragma mark - 38 | #pragma mark Generic utilities 39 | + (BOOL) runningInSimulator; 40 | 41 | #pragma mark - 42 | #pragma mark Helpers 43 | + (NSArray*) sortDescriptorsFromString:(NSString*)string; 44 | + (NSArray*) sortDescriptorsFromParameters:(id)parameters; 45 | + (NSURL*) URLWithSite:(NSString*)site andFormat:(NSString*)format andParameters:(id)parameters; 46 | 47 | #pragma mark - 48 | #pragma mark Predicates 49 | + (NSPredicate*) variablePredicateFromObject:(id)object; 50 | + (NSPredicate*) predicateFromObject:(id)object; 51 | + (NSPredicate*) equivalencyPredicateForKey:(NSString*)key; 52 | 53 | @end 54 | -------------------------------------------------------------------------------- /Examples/BasecampClient/BasecampClient-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIconFile 12 | Icon.png 13 | CFBundleIdentifier 14 | com.punkbot.${PRODUCT_NAME:rfc1034identifier} 15 | CFBundleInfoDictionaryVersion 16 | 6.0 17 | CFBundleName 18 | ${PRODUCT_NAME} 19 | CFBundlePackageType 20 | APPL 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | NSMainNibFile 28 | MainWindow 29 | 30 | 31 | -------------------------------------------------------------------------------- /Examples/BasecampClient/BasecampClient_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'BasecampClient' target in the 'BasecampClient' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #import 8 | #import 9 | #import "CoreUtils.h" 10 | #endif 11 | -------------------------------------------------------------------------------- /Examples/BasecampClient/Classes/BasecampClientAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // BasecampClientAppDelegate.h 3 | // BasecampClient 4 | // 5 | // Created by Mike Laurence on 3/6/10. 6 | // Copyright Punkbot LLC 2010. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CoreManager.h" 11 | 12 | 13 | @interface BasecampClientAppDelegate : NSObject { 14 | CoreManager *coreManager; 15 | 16 | UIWindow *window; 17 | UITabBarController *tabBarController; 18 | } 19 | 20 | @property (nonatomic, retain) CoreManager *coreManager; 21 | 22 | @property (nonatomic, retain) IBOutlet UIWindow *window; 23 | @property (nonatomic, retain) IBOutlet UITabBarController *tabBarController; 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /Examples/BasecampClient/Classes/BasecampClientAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // BasecampClientAppDelegate.m 3 | // BasecampClient 4 | // 5 | // Created by Mike Laurence on 3/6/10. 6 | // Copyright Punkbot LLC 2010. All rights reserved. 7 | // 8 | 9 | #import "BasecampClientAppDelegate.h" 10 | 11 | 12 | @implementation BasecampClientAppDelegate 13 | 14 | @synthesize coreManager; 15 | @synthesize window; 16 | @synthesize tabBarController; 17 | 18 | 19 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 20 | 21 | // Initialize Core Manager 22 | self.coreManager = [[[CoreManager alloc] init] autorelease]; 23 | coreManager.logLevel = 1; 24 | coreManager.remoteSiteURL = @"http://coreresource.Basecampapp.com"; 25 | 26 | [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque]; 27 | 28 | // Add the tab bar controller's current view as a subview of the window 29 | [window addSubview:tabBarController.view]; 30 | [window makeKeyAndVisible]; 31 | 32 | NSLog(@"Dict..."); 33 | NSLog(@"DICT: %@", $D(@"Key", @"Value", @"Key", @"Value")); 34 | 35 | return YES; 36 | } 37 | 38 | - (void) applicationWillTerminate:(UIApplication *)application { 39 | [coreManager save]; 40 | } 41 | 42 | 43 | 44 | - (void)dealloc { 45 | [coreManager release]; 46 | [tabBarController release]; 47 | [window release]; 48 | [super dealloc]; 49 | } 50 | 51 | @end 52 | 53 | -------------------------------------------------------------------------------- /Examples/BasecampClient/Classes/BasecampResource.h: -------------------------------------------------------------------------------- 1 | // 2 | // BasecampResource.h 3 | // BasecampClient 4 | // 5 | // Created by Mike Laurence on 3/6/10. 6 | // Copyright 2010 Mike Laurence. 7 | // 8 | 9 | #import 10 | #import "CoreResource.h" 11 | 12 | 13 | @interface BasecampResource : CoreResource { 14 | 15 | } 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /Examples/BasecampClient/Classes/BasecampResource.m: -------------------------------------------------------------------------------- 1 | // 2 | // BasecampResource.m 3 | // BasecampClient 4 | // 5 | // Created by Mike Laurence on 3/6/10. 6 | // Copyright 2010 Mike Laurence. 7 | // 8 | 9 | #import "BasecampResource.h" 10 | #import "NSString+InflectionSupport.h" 11 | 12 | 13 | @implementation BasecampResource 14 | 15 | + (NSString*) localNameForRemoteField:(NSString*)field { 16 | return [field camelize]; 17 | } 18 | 19 | + (NSString*) remoteNameForLocalField:(NSString*)field { 20 | return [field deCamelizeWith:@"_"]; 21 | } 22 | 23 | // Remove nesting from JSON response 24 | + (NSArray*) dataCollectionFromDeserializedCollection:(id)deserializedCollection { 25 | 26 | NSArray* collectionArray = [[[deserializedCollection objectAtIndex:0] allValues] objectAtIndex:0]; 27 | 28 | NSMutableArray* array = [NSMutableArray arrayWithCapacity:[collectionArray count]]; 29 | for (NSDictionary* dict in collectionArray) 30 | [array addObject:[[dict allValues] objectAtIndex:0]]; 31 | 32 | return array; 33 | } 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /Examples/BasecampClient/Icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikelaurence/CoreResource/9948473ed3ec33ab0c80d7ffc96cbb9e7cd338ad/Examples/BasecampClient/Icon.png -------------------------------------------------------------------------------- /Examples/BasecampClient/basecamp.xcdatamodel/elements: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikelaurence/CoreResource/9948473ed3ec33ab0c80d7ffc96cbb9e7cd338ad/Examples/BasecampClient/basecamp.xcdatamodel/elements -------------------------------------------------------------------------------- /Examples/BasecampClient/basecamp.xcdatamodel/layout: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikelaurence/CoreResource/9948473ed3ec33ab0c80d7ffc96cbb9e7cd338ad/Examples/BasecampClient/basecamp.xcdatamodel/layout -------------------------------------------------------------------------------- /Examples/BasecampClient/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // BasecampClient 4 | // 5 | // Created by Mike Laurence on 3/6/10. 6 | // Copyright Punkbot LLC 2010. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, char *argv[]) { 12 | NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 13 | int retVal = UIApplicationMain(argc, argv, nil, nil); 14 | [pool release]; 15 | return retVal; 16 | } 17 | 18 | -------------------------------------------------------------------------------- /Examples/CorePing/Classes/CorePingAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // CorePingAppDelegate.h 3 | // CorePing 4 | // 5 | // Created by Mike Laurence on 3/8/10. 6 | // Copyright Punkbot LLC 2010. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CoreManager.h" 11 | 12 | @interface CorePingAppDelegate : NSObject { 13 | CoreManager *coreManager; 14 | 15 | UIWindow *window; 16 | UINavigationController *navigationController; 17 | } 18 | 19 | @property (nonatomic, retain) IBOutlet UIWindow *window; 20 | @property (nonatomic, retain) IBOutlet UINavigationController *navigationController; 21 | 22 | @end 23 | 24 | -------------------------------------------------------------------------------- /Examples/CorePing/Classes/CorePingAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // CorePingAppDelegate.m 3 | // CorePing 4 | // 5 | // Created by Mike Laurence on 3/8/10. 6 | // Copyright Punkbot LLC 2010. All rights reserved. 7 | // 8 | 9 | #import "CorePingAppDelegate.h" 10 | #import "PingsController.h" 11 | 12 | 13 | @implementation CorePingAppDelegate 14 | 15 | @synthesize window; 16 | @synthesize navigationController; 17 | 18 | 19 | #pragma mark - 20 | #pragma mark Application lifecycle 21 | 22 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 23 | 24 | // Instantiate CoreManager 25 | coreManager = [[CoreManager alloc] init]; 26 | coreManager.remoteSiteURL = @"http://coreresource.org"; 27 | 28 | // Set up window & main view 29 | [window addSubview:[navigationController view]]; 30 | [window makeKeyAndVisible]; 31 | return YES; 32 | } 33 | 34 | 35 | - (void)applicationWillTerminate:(UIApplication *)application { 36 | [coreManager save]; 37 | } 38 | 39 | 40 | #pragma mark - 41 | #pragma mark Memory management 42 | 43 | - (void)dealloc { 44 | [coreManager release]; 45 | [navigationController release]; 46 | [window release]; 47 | [super dealloc]; 48 | } 49 | 50 | 51 | @end 52 | 53 | -------------------------------------------------------------------------------- /Examples/CorePing/Classes/Ping.h: -------------------------------------------------------------------------------- 1 | // 2 | // Ping.h 3 | // CorePing 4 | // 5 | // Created by Mike Laurence on 3/8/10. 6 | // Copyright 2010 Punkbot LLC. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CoreResource.h" 11 | 12 | 13 | @interface Ping : CoreResource {} 14 | 15 | @property (nonatomic, retain) NSDate *created_at; 16 | @property (nonatomic, retain) NSString *device; 17 | @property (nonatomic, retain) NSNumber *latitude; 18 | @property (nonatomic, retain) NSNumber *longitude; 19 | @property (nonatomic, retain) NSString *message; 20 | @property (nonatomic, retain) NSString *name; 21 | @property (nonatomic, retain) NSString *resourceId; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /Examples/CorePing/Classes/Ping.m: -------------------------------------------------------------------------------- 1 | // 2 | // Ping.m 3 | // CorePing 4 | // 5 | // Created by Mike Laurence on 3/8/10. 6 | // Copyright 2010 Punkbot LLC. All rights reserved. 7 | // 8 | 9 | #import "Ping.h" 10 | 11 | 12 | @implementation Ping 13 | 14 | @dynamic created_at; 15 | @dynamic device; 16 | @dynamic latitude; 17 | @dynamic longitude; 18 | @dynamic message; 19 | @dynamic name; 20 | @dynamic resourceId; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Examples/CorePing/Classes/PingsController.h: -------------------------------------------------------------------------------- 1 | // 2 | // PingsController.h 3 | // CorePing 4 | // 5 | // Created by Mike Laurence on 3/8/10. 6 | // Copyright Punkbot LLC 2010. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CoreTableController.h" 11 | 12 | @interface PingsController : CoreTableController { 13 | } 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /Examples/CorePing/Classes/PingsController.m: -------------------------------------------------------------------------------- 1 | // 2 | // PingsController.m 3 | // CorePing 4 | // 5 | // Created by Mike Laurence on 3/8/10. 6 | // Copyright Punkbot LLC 2010. All rights reserved. 7 | // 8 | 9 | #import "PingsController.h" 10 | #import "Ping.h" 11 | 12 | 13 | @implementation PingsController 14 | 15 | 16 | #pragma mark - 17 | #pragma mark View lifecycle 18 | 19 | - (void) loadView { [self loadTableView]; } 20 | 21 | - (void) viewWillAppear:(BOOL)animated { 22 | [Ping findAllRemote]; 23 | [[self coreResultsController] fetchWithSort:@"created_at DESC"]; 24 | } 25 | 26 | 27 | @end 28 | 29 | -------------------------------------------------------------------------------- /Examples/CorePing/CorePing-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIconFile 12 | 13 | CFBundleIdentifier 14 | com.yourcompany.${PRODUCT_NAME:rfc1034identifier} 15 | CFBundleInfoDictionaryVersion 16 | 6.0 17 | CFBundleName 18 | ${PRODUCT_NAME} 19 | CFBundlePackageType 20 | APPL 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | NSMainNibFile 28 | MainWindow 29 | 30 | 31 | -------------------------------------------------------------------------------- /Examples/CorePing/CorePing_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'CorePing' target in the 'CorePing' project 3 | // 4 | #import 5 | 6 | #ifndef __IPHONE_3_0 7 | #warning "This project uses features only available in iPhone SDK 3.0 and later." 8 | #endif 9 | 10 | 11 | #ifdef __OBJC__ 12 | #import 13 | #import 14 | #import 15 | #import "CoreUtils.h" 16 | #endif 17 | -------------------------------------------------------------------------------- /Examples/CorePing/coreping.xcdatamodel/elements: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikelaurence/CoreResource/9948473ed3ec33ab0c80d7ffc96cbb9e7cd338ad/Examples/CorePing/coreping.xcdatamodel/elements -------------------------------------------------------------------------------- /Examples/CorePing/coreping.xcdatamodel/layout: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikelaurence/CoreResource/9948473ed3ec33ab0c80d7ffc96cbb9e7cd338ad/Examples/CorePing/coreping.xcdatamodel/layout -------------------------------------------------------------------------------- /Examples/CorePing/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // CorePing 4 | // 5 | // Created by Mike Laurence on 3/8/10. 6 | // Copyright Punkbot LLC 2010. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, char *argv[]) { 12 | 13 | NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 14 | int retVal = UIApplicationMain(argc, argv, nil, nil); 15 | [pool release]; 16 | return retVal; 17 | } 18 | -------------------------------------------------------------------------------- /Examples/CorePingPlus/Classes/CorePingPlusAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // CorePingPlusAppDelegate.h 3 | // CorePing 4 | // 5 | // Created by Mike Laurence on 3/8/10. 6 | // Copyright Punkbot LLC 2010. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CoreManager.h" 11 | 12 | @interface CorePingPlusAppDelegate : NSObject { 13 | CoreManager *coreManager; 14 | 15 | UIWindow *window; 16 | UINavigationController *navigationController; 17 | } 18 | 19 | @property (nonatomic, retain) IBOutlet UIWindow *window; 20 | @property (nonatomic, retain) IBOutlet UINavigationController *navigationController; 21 | 22 | @end 23 | 24 | -------------------------------------------------------------------------------- /Examples/CorePingPlus/Classes/CorePingPlusAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // CorePingPlusAppDelegate.m 3 | // CorePing 4 | // 5 | // Created by Mike Laurence on 3/8/10. 6 | // Copyright Punkbot LLC 2010. All rights reserved. 7 | // 8 | 9 | #import "CorePingPlusAppDelegate.h" 10 | #import "PingsController.h" 11 | 12 | 13 | @implementation CorePingPlusAppDelegate 14 | 15 | @synthesize window; 16 | @synthesize navigationController; 17 | 18 | 19 | #pragma mark - 20 | #pragma mark Application lifecycle 21 | 22 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 23 | 24 | // Instantiate CoreManager 25 | coreManager = [[CoreManager alloc] init]; 26 | coreManager.remoteSiteURL = @"http://coreresource.org"; 27 | [coreManager.defaultDateParser setDateFormat:@"EEE MMM dd HH:mm:ss 'UTC' yyyy"]; 28 | 29 | // Set up window & main view 30 | [window addSubview:[navigationController view]]; 31 | [window makeKeyAndVisible]; 32 | return YES; 33 | } 34 | 35 | 36 | - (void)applicationWillTerminate:(UIApplication *)application { 37 | [coreManager save]; 38 | } 39 | 40 | 41 | #pragma mark - 42 | #pragma mark Memory management 43 | 44 | - (void)dealloc { 45 | [coreManager release]; 46 | [navigationController release]; 47 | [window release]; 48 | [super dealloc]; 49 | } 50 | 51 | 52 | @end 53 | 54 | -------------------------------------------------------------------------------- /Examples/CorePingPlus/Classes/Ping.h: -------------------------------------------------------------------------------- 1 | // 2 | // Ping.h 3 | // CorePing 4 | // 5 | // Created by Mike Laurence on 3/8/10. 6 | // Copyright 2010 Punkbot LLC. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CoreResource.h" 11 | 12 | 13 | @interface Ping : CoreResource {} 14 | 15 | @property (nonatomic, retain) NSDate *created_at; 16 | @property (nonatomic, retain) NSString *device; 17 | @property (nonatomic, retain) NSNumber *latitude; 18 | @property (nonatomic, retain) NSNumber *longitude; 19 | @property (nonatomic, retain) NSString *message; 20 | @property (nonatomic, retain) NSString *name; 21 | @property (nonatomic, retain) NSString *resourceId; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /Examples/CorePingPlus/Classes/Ping.m: -------------------------------------------------------------------------------- 1 | // 2 | // Ping.m 3 | // CorePing 4 | // 5 | // Created by Mike Laurence on 3/8/10. 6 | // Copyright 2010 Punkbot LLC. All rights reserved. 7 | // 8 | 9 | #import "Ping.h" 10 | 11 | 12 | @implementation Ping 13 | 14 | @dynamic created_at; 15 | @dynamic device; 16 | @dynamic latitude; 17 | @dynamic longitude; 18 | @dynamic message; 19 | @dynamic name; 20 | @dynamic resourceId; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Examples/CorePingPlus/Classes/PingController.h: -------------------------------------------------------------------------------- 1 | // 2 | // PingController.h 3 | // CorePingPlus 4 | // 5 | // Created by Mike Laurence on 3/9/10. 6 | // Copyright 2010 Punkbot LLC. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | @interface PingController : UIViewController { 13 | UITextField *nameField; 14 | UITextView *messageField; 15 | } 16 | 17 | @property (nonatomic, retain) IBOutlet UITextField *nameField; 18 | @property (nonatomic, retain) IBOutlet UITextView *messageField; 19 | 20 | - (IBAction) submit; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Examples/CorePingPlus/Classes/PingController.m: -------------------------------------------------------------------------------- 1 | // 2 | // PingController.m 3 | // CorePingPlus 4 | // 5 | // Created by Mike Laurence on 3/9/10. 6 | // Copyright 2010 Punkbot LLC. All rights reserved. 7 | // 8 | 9 | #import "PingController.h" 10 | #import 11 | #import "CoreManager.h" 12 | #import "ASIFormDataRequest.h" 13 | 14 | 15 | @implementation PingController 16 | 17 | @synthesize nameField, messageField; 18 | 19 | - (void) viewDidLoad { 20 | messageField.layer.cornerRadius = 5.0; 21 | messageField.layer.borderWidth = 1.0; 22 | } 23 | 24 | - (void) viewWillAppear:(BOOL)animated { 25 | [nameField becomeFirstResponder]; 26 | } 27 | 28 | - (IBAction) submit { 29 | // Simple ASI form request until CoreResource#create methods are done 30 | ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:[NSURL URLWithString:@"http://coreresource.org/pings"]]; 31 | [request setPostValue:(nameField.text != nil && [nameField.text length] > 0 ? nameField.text : @"Anonymous Coward") forKey:@"name"]; 32 | [request setPostValue:messageField.text forKey:@"message"]; 33 | [request setPostValue:[[UIDevice currentDevice] model] forKey:@"device"]; 34 | [[CoreManager main] enqueueRequest:request]; 35 | 36 | [self dismissModalViewControllerAnimated:YES]; 37 | } 38 | 39 | @end 40 | -------------------------------------------------------------------------------- /Examples/CorePingPlus/Classes/PingsController.h: -------------------------------------------------------------------------------- 1 | // 2 | // PingsController.h 3 | // CorePing 4 | // 5 | // Created by Mike Laurence on 3/8/10. 6 | // Copyright Punkbot LLC 2010. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CoreTableController.h" 11 | 12 | @interface PingsController : CoreTableController { 13 | } 14 | 15 | - (IBAction) refresh; 16 | - (IBAction) compose; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /Examples/CorePingPlus/Classes/PingsController.m: -------------------------------------------------------------------------------- 1 | // 2 | // PingsController.m 3 | // CorePing 4 | // 5 | // Created by Mike Laurence on 3/8/10. 6 | // Copyright Punkbot LLC 2010. All rights reserved. 7 | // 8 | 9 | #import "PingsController.h" 10 | #import "Ping.h" 11 | #import "DynamicCell.h" 12 | #import "NSDate+Helper.h" 13 | #import "PingController.h" 14 | 15 | 16 | @implementation PingsController 17 | 18 | 19 | #pragma mark - 20 | #pragma mark View lifecycle 21 | 22 | - (void) loadView { [self loadTableView]; } 23 | 24 | - (void) viewWillAppear:(BOOL)animated { 25 | [self refresh]; 26 | [[self coreResultsController] fetchWithSort:@"created_at DESC"]; 27 | } 28 | 29 | 30 | #pragma mark - 31 | #pragma mark Actions 32 | 33 | - (IBAction) refresh { 34 | [Ping findAllRemote]; 35 | } 36 | 37 | - (IBAction) compose { 38 | [self presentModalViewController:[[[PingController alloc] initWithNibName:nil bundle:nil] autorelease] animated:YES]; 39 | } 40 | 41 | 42 | #pragma mark - 43 | #pragma mark Table view methods 44 | 45 | - (UITableViewCell*) tableView:(UITableView*)tableView resultCellForRowAtIndexPath:(NSIndexPath*)indexPath { 46 | 47 | Ping *ping = (Ping*)[self resourceAtIndexPath:indexPath]; 48 | 49 | DynamicCell* cell = (DynamicCell*) [tableView dequeueReusableCellWithIdentifier:@"PingCell"]; 50 | if (cell == nil) { 51 | cell = [DynamicCell cellWithReuseIdentifier:@"PingCell"]; 52 | cell.selectionStyle = UITableViewCellSelectionStyleNone; 53 | cell.defaultFont = [UIFont systemFontOfSize:15.0]; 54 | } 55 | 56 | [cell reset]; 57 | [cell addLabelWithText:ping.name andFont:[UIFont boldSystemFontOfSize:19.0]]; 58 | [cell addLabelWithText:ping.message]; 59 | UILabel *createdAtLabel = [cell addLabelWithText:[ping.created_at stringDaysAgo]]; 60 | createdAtLabel.textColor = [UIColor grayColor]; 61 | [cell prepare]; 62 | 63 | return cell; 64 | } 65 | 66 | 67 | @end 68 | 69 | -------------------------------------------------------------------------------- /Examples/CorePingPlus/CorePingPlus-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIconFile 12 | 13 | CFBundleIdentifier 14 | org.coreresource.${PRODUCT_NAME:rfc1034identifier} 15 | CFBundleInfoDictionaryVersion 16 | 6.0 17 | CFBundleName 18 | ${PRODUCT_NAME} 19 | CFBundlePackageType 20 | APPL 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | NSMainNibFile 28 | MainWindow 29 | 30 | 31 | -------------------------------------------------------------------------------- /Examples/CorePingPlus/CorePingPlus_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'CorePing' target in the 'CorePing' project 3 | // 4 | #import 5 | 6 | #ifndef __IPHONE_3_0 7 | #warning "This project uses features only available in iPhone SDK 3.0 and later." 8 | #endif 9 | 10 | 11 | #ifdef __OBJC__ 12 | #import 13 | #import 14 | #import 15 | #import "CoreUtils.h" 16 | #endif 17 | -------------------------------------------------------------------------------- /Examples/CorePingPlus/corepingplus.xcdatamodel/elements: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikelaurence/CoreResource/9948473ed3ec33ab0c80d7ffc96cbb9e7cd338ad/Examples/CorePingPlus/corepingplus.xcdatamodel/elements -------------------------------------------------------------------------------- /Examples/CorePingPlus/corepingplus.xcdatamodel/layout: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikelaurence/CoreResource/9948473ed3ec33ab0c80d7ffc96cbb9e7cd338ad/Examples/CorePingPlus/corepingplus.xcdatamodel/layout -------------------------------------------------------------------------------- /Examples/CorePingPlus/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // CorePing 4 | // 5 | // Created by Mike Laurence on 3/8/10. 6 | // Copyright Punkbot LLC 2010. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, char *argv[]) { 12 | 13 | NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 14 | int retVal = UIApplicationMain(argc, argv, nil, nil); 15 | [pool release]; 16 | return retVal; 17 | } 18 | -------------------------------------------------------------------------------- /Examples/CoreTest/Classes/Artist.h: -------------------------------------------------------------------------------- 1 | // 2 | // Artist.h 3 | // CoreTest 4 | // 5 | // Created by Mike Laurence on 1/14/10. 6 | // Copyright 2010 Punkbot LLC. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CoreResource.h" 11 | 12 | 13 | @interface Artist : CoreResource { 14 | } 15 | 16 | @property (nonatomic, retain) NSString * detail; 17 | @property (nonatomic, retain) NSString * name; 18 | @property (nonatomic, retain) NSNumber * resourceId; 19 | @property (nonatomic, retain) NSSet * songs; 20 | @property (nonatomic, retain) NSString * summary; 21 | @property (nonatomic, retain) NSDate * updatedAt; 22 | 23 | - (NSArray*) sortedSongs; 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /Examples/CoreTest/Classes/Artist.m: -------------------------------------------------------------------------------- 1 | // 2 | // Artist.m 3 | // CoreTest 4 | // 5 | // Created by Mike Laurence on 1/14/10. 6 | // Copyright 2010 Punkbot LLC. All rights reserved. 7 | // 8 | 9 | #import "Artist.h" 10 | #import "CoreUtils.h" 11 | 12 | 13 | @implementation Artist 14 | 15 | @dynamic detail; 16 | @dynamic name; 17 | @dynamic resourceId; 18 | @dynamic songs; 19 | @dynamic summary; 20 | @dynamic updatedAt; 21 | 22 | - (NSArray*) sortedSongs { 23 | return [[self.songs allObjects] sortedArrayUsingDescriptors:[CoreUtils sortDescriptorsFromString:@"name ASC"]]; 24 | } 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /Examples/CoreTest/Classes/ArtistCollectionController.h: -------------------------------------------------------------------------------- 1 | // 2 | // ArtistCollectionController.h 3 | // CoreTest 4 | // 5 | // Created by Mike Laurence on 1/14/10. 6 | // Copyright Punkbot LLC 2010. All rights reserved. 7 | // 8 | 9 | #import "CoreTableController.h" 10 | 11 | @interface ArtistCollectionController : CoreTableController { 12 | } 13 | 14 | - (IBAction) findAll:(id)sender; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /Examples/CoreTest/Classes/ArtistCollectionController.m: -------------------------------------------------------------------------------- 1 | // 2 | // ArtistCollectionController.m 3 | // CoreTest 4 | // 5 | // Created by Mike Laurence on 1/14/10. 6 | // Copyright Punkbot LLC 2010. All rights reserved. 7 | // 8 | 9 | #import "ArtistCollectionController.h" 10 | 11 | 12 | @implementation ArtistCollectionController 13 | 14 | #pragma mark - 15 | #pragma mark Actions 16 | 17 | - (IBAction) findAll:(id)sender { 18 | 19 | 20 | 21 | } 22 | 23 | 24 | #pragma mark - 25 | #pragma mark Table view methods 26 | 27 | // Customize the appearance of table view cells. 28 | - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath { 29 | 30 | static NSString *CellIdentifier = @"Cell"; 31 | 32 | UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier]; 33 | if (cell == nil) { 34 | cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease]; 35 | } 36 | 37 | // Configure the cell. 38 | 39 | return cell; 40 | } 41 | 42 | // Override to support row selection in the table view. 43 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 44 | 45 | // Navigation logic may go here -- for example, create and push another view controller. 46 | // AnotherViewController *anotherViewController = [[AnotherViewController alloc] initWithNibName:@"AnotherView" bundle:nil]; 47 | // [self.navigationController pushViewController:anotherViewController animated:YES]; 48 | // [anotherViewController release]; 49 | } 50 | 51 | 52 | /* 53 | // Override to support conditional editing of the table view. 54 | - (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath { 55 | // Return NO if you do not want the specified item to be editable. 56 | return YES; 57 | } 58 | */ 59 | 60 | 61 | /* 62 | // Override to support editing the table view. 63 | - (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath { 64 | 65 | if (editingStyle == UITableViewCellEditingStyleDelete) { 66 | // Delete the row from the data source. 67 | [tableView deleteRowsAtIndexPaths:[NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade]; 68 | } 69 | else if (editingStyle == UITableViewCellEditingStyleInsert) { 70 | // Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view. 71 | } 72 | } 73 | */ 74 | 75 | - (void)dealloc { 76 | [super dealloc]; 77 | } 78 | 79 | 80 | @end 81 | 82 | -------------------------------------------------------------------------------- /Examples/CoreTest/Classes/CoreTestAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // CoreTestAppDelegate.h 3 | // CoreTest 4 | // 5 | // Created by Mike Laurence on 1/14/10. 6 | // Copyright Punkbot LLC 2010. All rights reserved. 7 | // 8 | 9 | #import "GHUnitIPhoneAppDelegate.h" 10 | #import "CoreManager.h" 11 | 12 | @interface CoreTestAppDelegate : GHUnitIPhoneAppDelegate { 13 | UIWindow *window; 14 | UINavigationController *navigationController; 15 | } 16 | 17 | @property (nonatomic, retain) IBOutlet UIWindow *window; 18 | @property (nonatomic, retain) IBOutlet UINavigationController *navigationController; 19 | 20 | @end 21 | 22 | -------------------------------------------------------------------------------- /Examples/CoreTest/Classes/CoreTestAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // CoreTestAppDelegate.m 3 | // CoreTest 4 | // 5 | // Created by Mike Laurence on 1/14/10. 6 | // Copyright Punkbot LLC 2010. All rights reserved. 7 | // 8 | 9 | #import "CoreTestAppDelegate.h" 10 | 11 | 12 | @implementation CoreTestAppDelegate 13 | 14 | @synthesize window; 15 | @synthesize navigationController; 16 | 17 | 18 | #pragma mark - 19 | #pragma mark Application lifecycle 20 | 21 | - (void)applicationDidFinishLaunching:(UIApplication *)application { 22 | 23 | [window addSubview:[navigationController view]]; 24 | [window makeKeyAndVisible]; 25 | 26 | [super applicationDidFinishLaunching:application]; 27 | } 28 | 29 | 30 | - (void)applicationWillTerminate:(UIApplication *)application { 31 | // Save data if appropriate 32 | } 33 | 34 | 35 | #pragma mark - 36 | #pragma mark Memory management 37 | 38 | - (void)dealloc { 39 | [navigationController release]; 40 | [window release]; 41 | [super dealloc]; 42 | } 43 | 44 | 45 | @end 46 | 47 | -------------------------------------------------------------------------------- /Examples/CoreTest/Classes/Song.h: -------------------------------------------------------------------------------- 1 | // 2 | // Song.h 3 | // CoreTest 4 | // 5 | // Created by Mike Laurence on 1/25/10. 6 | // Copyright 2010 Punkbot LLC. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CoreResource.h" 11 | 12 | @class Artist; 13 | 14 | @interface Song : CoreResource { 15 | } 16 | 17 | @property (nonatomic, retain) NSString *name; 18 | @property (nonatomic, retain) NSNumber *resourceId; 19 | 20 | @property (nonatomic, retain) Artist *artist; 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Examples/CoreTest/Classes/Song.m: -------------------------------------------------------------------------------- 1 | // 2 | // Song.m 3 | // CoreTest 4 | // 5 | // Created by Mike Laurence on 1/25/10. 6 | // Copyright 2010 Punkbot LLC. All rights reserved. 7 | // 8 | 9 | #import "Song.h" 10 | 11 | 12 | @implementation Song 13 | 14 | @dynamic name; 15 | @dynamic resourceId; 16 | 17 | @dynamic artist; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /Examples/CoreTest/Classes/User.h: -------------------------------------------------------------------------------- 1 | // 2 | // User.h 3 | // CoreTest 4 | // 5 | // Created by Mike Laurence on 1/25/10. 6 | // Copyright 2010 Punkbot LLC. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CoreResource.h" 11 | 12 | 13 | @interface User : CoreResource { 14 | 15 | } 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /Examples/CoreTest/Classes/User.m: -------------------------------------------------------------------------------- 1 | // 2 | // User.m 3 | // CoreTest 4 | // 5 | // Created by Mike Laurence on 1/25/10. 6 | // Copyright 2010 Punkbot LLC. All rights reserved. 7 | // 8 | 9 | #import "User.h" 10 | 11 | 12 | @implementation User 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /Examples/CoreTest/CoreResourceConfigurationTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // CoreResourceConfigurationTests.m 3 | // CoreTest 4 | // 5 | // Created by Mike Laurence on 1/19/10. 6 | // Copyright 2010 Mike Laurence. All rights reserved. 7 | // 8 | 9 | #import "CoreResourceTestCase.h" 10 | 11 | @interface CoreResourceConfigurationTests : CoreResourceTestCase {} 12 | @end 13 | 14 | @implementation CoreResourceConfigurationTests 15 | 16 | #pragma mark - 17 | #pragma mark Tests - Configuration 18 | 19 | - (void) testPropertyDescriptionForField { 20 | NSDictionary* props = [[Artist entityDescription] propertiesByName]; 21 | GHAssertNotNil([Artist propertyDescriptionForField:@"name"], nil); 22 | GHAssertNotNil([Artist propertyDescriptionForField:@"summary"], nil); 23 | GHAssertEquals([Artist propertyDescriptionForField:@"name"], [props objectForKey:@"name"], nil); 24 | GHAssertEquals([Artist propertyDescriptionForField:@"summary"], [props objectForKey:@"summary"], nil); 25 | } 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /Examples/CoreTest/CoreResourceCoreDataTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // CoreResourceCoreDataTests.m 3 | // CoreTest 4 | // 5 | // Created by Mike Laurence on 1/19/10. 6 | // Copyright 2010 Mike Laurence. All rights reserved. 7 | // 8 | 9 | #import "CoreResourceTestCase.h" 10 | #import "Artist.h" 11 | #import "Song.h" 12 | #import "User.h" 13 | 14 | @interface CoreResourceCoreDataTests : CoreResourceTestCase {} 15 | @end 16 | 17 | @implementation CoreResourceCoreDataTests 18 | 19 | #pragma mark - 20 | #pragma mark Core Data 21 | 22 | - (void) testEntityName { 23 | GHAssertEqualStrings([Artist entityName], @"Artist", nil); 24 | GHAssertEqualStrings([Song entityName], @"Song", nil); 25 | } 26 | 27 | - (void) testEntityDescription { 28 | NSEntityDescription* artistDescription = [NSEntityDescription entityForName:@"Artist" inManagedObjectContext:[coreManager managedObjectContext]]; 29 | GHAssertEquals([Artist entityDescription], artistDescription, nil); 30 | } 31 | 32 | - (void) testHasRelationships { 33 | GHAssertTrue([Artist hasRelationships], nil); 34 | GHAssertTrue([Song hasRelationships], nil); 35 | GHAssertFalse([User hasRelationships], nil); 36 | } 37 | 38 | @end 39 | -------------------------------------------------------------------------------- /Examples/CoreTest/CoreResourceCreateTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // CoreResourceCreateTests.m 3 | // CoreTest 4 | // 5 | // Created by Mike Laurence on 1/19/10. 6 | // Copyright 2010 Mike Laurence. All rights reserved. 7 | // 8 | 9 | #import "CoreResourceTestCase.h" 10 | 11 | @interface CoreResourceCreateTests : CoreResourceTestCase {} 12 | @end 13 | 14 | @implementation CoreResourceCreateTests 15 | 16 | #pragma mark - 17 | #pragma mark Create 18 | 19 | - (void) testCreate { 20 | Artist* artistOne = [Artist create:[self artistData:0]]; 21 | [self validateFirstArtist:artistOne]; 22 | 23 | Artist* artistTwo = [Artist create:[self artistData:1]]; 24 | [self validateSecondArtist:artistTwo]; 25 | } 26 | 27 | /* 28 | - (void) testCreateOrUpdateWithDictionary { GHFail(nil); } 29 | - (void) testCreateOrUpdateWithDictionaryAndRelationship { GHFail(nil); } 30 | */ 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /Examples/CoreTest/CoreResourceDestroyTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // CoreResourceDestroyTests.m 3 | // CoreTest 4 | // 5 | // Created by Mike Laurence on 1/19/10. 6 | // Copyright 2010 Mike Laurence. All rights reserved. 7 | // 8 | 9 | #import "CoreResourceTestCase.h" 10 | 11 | @interface CoreResourceDestroyTests : CoreResourceTestCase {} 12 | @end 13 | 14 | @implementation CoreResourceDestroyTests 15 | 16 | #pragma mark - 17 | #pragma mark Results Management 18 | 19 | - (void) testDestroyAllLocal { 20 | [self loadAllArtists]; 21 | GHAssertTrue([[Artist findAllLocal] resourceCount] > 0, nil); 22 | [Artist destroyAllLocal]; 23 | GHAssertEquals([[Artist findAllLocal] resourceCount], 0, nil); 24 | } 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /Examples/CoreTest/CoreResourceResultsTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // CoreResourceResultsTests.m 3 | // CoreTest 4 | // 5 | // Created by Mike Laurence on 1/19/10. 6 | // Copyright 2010 Mike Laurence. All rights reserved. 7 | // 8 | 9 | #import "CoreResourceTestCase.h" 10 | 11 | @interface CoreResourceResultsTests : CoreResourceTestCase {} 12 | @end 13 | 14 | @implementation CoreResourceResultsTests 15 | 16 | #pragma mark - 17 | #pragma mark Results Management 18 | /* 19 | - (void) testFetchRequest { GHFail(nil); } 20 | - (void) testFetchRequestWithSortAndPredicate { GHFail(nil); } 21 | - (void) testPredicateWithParameters { GHFail(nil); } 22 | - (void) testCoreResultsControllerWithSortAndSection { GHFail(nil); } 23 | - (void) testCoreResultsControllerWithRequestAndSectionKey { GHFail(nil); } 24 | */ 25 | 26 | - (void) testFastEnumeration { 27 | for (Artist* artist in [Artist findAll]) 28 | GHAssertTrue([artist isKindOfClass:[Artist class]], nil); 29 | 30 | for (Artist* artist in [Artist find:$I(-1)]) 31 | GHFail(@"No objects should be iterated over in [Artist find:-1]"); 32 | } 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /Examples/CoreTest/CoreResourceTestCase.h: -------------------------------------------------------------------------------- 1 | // 2 | // CoreResourceTestCase.h 3 | // CoreTest 4 | // 5 | // Created by Mike Laurence on 1/19/10. 6 | // Copyright 2010 Mike Laurence. All rights reserved. 7 | // 8 | 9 | #import "GHUnit.h" 10 | #import "Artist.h" 11 | #import "Song.h" 12 | #import "CoreUtils.h" 13 | #import "CoreResult.h" 14 | 15 | @interface CoreResourceTestCase : GHAsyncTestCase { 16 | CoreManager *coreManager; 17 | NSMutableDictionary* delegatesCalled; 18 | } 19 | 20 | @property (nonatomic, retain) NSMutableDictionary* delegatesCalled; 21 | 22 | - (NSString*) artistDataJSON:(NSString*)file; 23 | - (NSDictionary*) artistData:(int)index; 24 | - (void) loadAllArtists; 25 | - (Artist*) loadArtist:(int)index; 26 | - (Artist*) loadArtist:(int)index andSave:(BOOL)shouldSave; 27 | - (Artist*) loadArtist:(int)index inContext:(NSManagedObjectContext*)context; 28 | - (Artist*) loadArtist:(int)index andSave:(BOOL)shouldSave inContext:(NSManagedObjectContext*)context; 29 | - (NSArray*) allLocalArtists; 30 | - (void) validateFirstArtist:(Artist*)artist; 31 | - (void) validateSecondArtist:(Artist*)artist; 32 | 33 | #pragma mark - 34 | #pragma mark Sorting 35 | NSInteger ascendingSort(id obj1, id obj2, void *key); 36 | 37 | 38 | @end -------------------------------------------------------------------------------- /Examples/CoreTest/CoreResourceTestCase.m: -------------------------------------------------------------------------------- 1 | // 2 | // CoreResourceTestCase.m 3 | // CoreTest 4 | // 5 | // Created by Mike Laurence on 1/19/10. 6 | // Copyright 2010 Mike Laurence. All rights reserved. 7 | // 8 | 9 | #import "CoreResourceTestCase.h" 10 | 11 | @implementation CoreResourceTestCase 12 | 13 | @synthesize delegatesCalled; 14 | 15 | static int dbInc = 1; 16 | 17 | #pragma mark - 18 | #pragma mark Convenience methods 19 | 20 | - (NSString*) artistDataJSON:(NSString*)file { 21 | NSError* parseError; 22 | return [NSString stringWithContentsOfFile: 23 | [[NSBundle mainBundle] pathForResource:file ofType:@"json"] 24 | encoding:NSUTF8StringEncoding error:&parseError]; 25 | } 26 | 27 | - (NSDictionary*) artistData:(int)index { 28 | return [[self artistDataJSON:[NSString stringWithFormat:@"artists.%@", [NSNumber numberWithInt:index]]] JSONValue]; 29 | } 30 | 31 | - (void) loadAllArtists { 32 | [self loadArtist:0]; 33 | [self loadArtist:1]; 34 | [self loadArtist:2]; 35 | } 36 | 37 | - (Artist*) loadArtist:(int)index { 38 | return [self loadArtist:index inContext:[coreManager managedObjectContext]]; 39 | } 40 | 41 | - (Artist*) loadArtist:(int)index andSave:(BOOL)shouldSave { 42 | return [self loadArtist:index andSave:shouldSave inContext:[coreManager managedObjectContext]]; 43 | } 44 | 45 | - (Artist*) loadArtist:(int)index inContext:(NSManagedObjectContext*)context { 46 | return [self loadArtist:index andSave:YES inContext:context]; 47 | } 48 | 49 | - (Artist*) loadArtist:(int)index andSave:(BOOL)shouldSave inContext:(NSManagedObjectContext*)context { 50 | Artist* artist = [NSEntityDescription insertNewObjectForEntityForName:@"Artist" inManagedObjectContext:context]; 51 | NSDictionary* dict = [self artistData:index]; 52 | artist.resourceId = [dict objectForKey:@"id"]; 53 | artist.name = [dict objectForKey:@"name"]; 54 | artist.summary = [dict objectForKey:@"summary"]; 55 | artist.detail = [dict objectForKey:@"detail"]; 56 | artist.updatedAt = [[coreManager defaultDateParser] dateFromString:[dict objectForKey:@"updatedAt"]]; 57 | 58 | NSDictionary* songsArray = [dict objectForKey:@"songs"]; 59 | NSMutableSet* songs = [NSMutableSet set]; 60 | if (songsArray) { 61 | for (NSDictionary* dict in songsArray) { 62 | Song* song = [NSEntityDescription insertNewObjectForEntityForName:@"Song" inManagedObjectContext:context]; 63 | song.resourceId = [dict objectForKey:@"id"]; 64 | song.name = [dict objectForKey:@"name"]; 65 | [songs addObject:song]; 66 | } 67 | artist.songs = songs; 68 | } 69 | 70 | if (shouldSave) { 71 | NSError *error = nil; 72 | [context save:&error]; 73 | } 74 | 75 | return artist; 76 | } 77 | 78 | - (NSArray*) allLocalArtists { 79 | NSError* error = nil; 80 | NSArray* artists = [[Artist managedObjectContext] executeFetchRequest:[Artist fetchRequestWithSort:@"resourceId ASC" andPredicate:nil] error:&error]; 81 | GHAssertNULL(error, @"There should be no errors in the allLocalArtists convenience method"); 82 | NSLog(@"%i local artists", [artists count]); 83 | return artists != nil ? artists : [NSArray array]; 84 | } 85 | 86 | - (void) validateFirstArtist:(Artist*)artist { 87 | GHAssertEqualStrings(artist.name, @"Peter Gabriel", nil); 88 | GHAssertEqualStrings(artist.summary, @"Peter Brian Gabriel is an English musician and songwriter.", nil); 89 | GHAssertEquals([artist.resourceId intValue], 0, nil); 90 | } 91 | 92 | - (void) validateSecondArtist:(Artist*)artist { 93 | GHAssertEqualStrings(artist.name, @"Spoon", nil); 94 | GHAssertEqualStrings(artist.summary, @"Spoon is an American indie rock band from Austin, Texas.", nil); 95 | GHAssertEquals([artist.resourceId intValue], 1, nil); 96 | GHAssertEquals((NSInteger) [artist.songs count], 2, nil); 97 | GHAssertEqualStrings(((Song*)[[artist sortedSongs] objectAtIndex:0]).name, @"Don't Make Me a Target", nil); 98 | GHAssertEqualStrings(((Song*)[[artist sortedSongs] objectAtIndex:1]).name, @"You Got Yr. Cherry Bomb", nil); 99 | } 100 | 101 | 102 | 103 | #pragma mark - 104 | #pragma mark GHUnit Configuration 105 | 106 | - (void) setUp { 107 | NSString *dbName = $S(@"db-%i-%i.sqlite", [NSDate timeIntervalSinceReferenceDate], dbInc++); 108 | NSLog(@"\n\nCreating core manager with DB named '%@'\n\n", dbName); 109 | coreManager = [[CoreManager alloc] initWithOptions:$D(dbName, @"dbName")]; 110 | coreManager.logLevel = 2; 111 | coreManager.useBundleRequests = YES; 112 | coreManager.bundleRequestDelay = 0.01; 113 | [CoreManager setMain:coreManager]; 114 | } 115 | 116 | - (void) tearDown { 117 | [coreManager release]; 118 | coreManager = nil; 119 | } 120 | 121 | 122 | @end -------------------------------------------------------------------------------- /Examples/CoreTest/CoreResourceUpdateTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // CoreResourceUpdateTests.m 3 | // CoreTest 4 | // 5 | // Created by Mike Laurence on 1/19/10. 6 | // Copyright 2010 Mike Laurence. All rights reserved. 7 | // 8 | 9 | #import "CoreResourceTestCase.h" 10 | 11 | @interface CoreResourceUpdateTests : CoreResourceTestCase {} 12 | @end 13 | 14 | @implementation CoreResourceUpdateTests 15 | 16 | - (void) testUpdateWithDictionary { 17 | [self loadArtist:0]; 18 | NSDictionary* updateDict = [[self artistDataJSON:@"artists.0.update"] JSONValue]; 19 | 20 | Artist* artist = (Artist*)[[Artist findLocal:[NSNumber numberWithInt:0]] resource]; 21 | [artist update:updateDict]; 22 | 23 | GHAssertEqualStrings(artist.name, @"Peter B. Gabriel", nil); 24 | GHAssertEqualStrings(artist.summary, @"Peter Brian Gabriel is a musician and songwriter.", nil); 25 | } 26 | 27 | //- (void) testShouldUpdateWithDictionary { GHFail(nil); } 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /Examples/CoreTest/CoreTest-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIconFile 12 | 13 | CFBundleIdentifier 14 | org.coreresource.${PRODUCT_NAME:rfc1034identifier} 15 | CFBundleInfoDictionaryVersion 16 | 6.0 17 | CFBundleName 18 | ${PRODUCT_NAME} 19 | CFBundlePackageType 20 | APPL 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | NSMainNibFile 28 | 29 | 30 | 31 | -------------------------------------------------------------------------------- /Examples/CoreTest/CoreTest.xcdatamodel/elements: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikelaurence/CoreResource/9948473ed3ec33ab0c80d7ffc96cbb9e7cd338ad/Examples/CoreTest/CoreTest.xcdatamodel/elements -------------------------------------------------------------------------------- /Examples/CoreTest/CoreTest.xcdatamodel/layout: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikelaurence/CoreResource/9948473ed3ec33ab0c80d7ffc96cbb9e7cd338ad/Examples/CoreTest/CoreTest.xcdatamodel/layout -------------------------------------------------------------------------------- /Examples/CoreTest/CoreUtilsTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // CoreUtilsTests.m 3 | // CoreTest 4 | // 5 | // Created by Mike Laurence on 3/8/10. 6 | // Copyright 2010 Mike Laurence. All rights reserved. 7 | // 8 | 9 | #import "CoreResourceTestCase.h" 10 | 11 | @interface CoreUtilsTests : CoreResourceTestCase {} 12 | @end 13 | 14 | @implementation CoreUtilsTests 15 | 16 | - (void) testDictionaryMacro { 17 | NSDictionary* d1 = [NSDictionary dictionaryWithObjectsAndKeys:@"valueOne", @"keyOne", @"valueTwo", @"keyTwo", nil]; 18 | NSDictionary* d2 = $D(@"valueOne", @"keyOne", @"valueTwo", @"keyTwo"); 19 | GHAssertEquals([d1 count], [d2 count], nil); 20 | GHAssertEqualStrings([d1 objectForKey:@"keyOne"], [d2 objectForKey:@"keyOne"], nil); 21 | GHAssertEqualStrings([d1 objectForKey:@"keyTwo"], [d2 objectForKey:@"keyTwo"], nil); 22 | } 23 | 24 | - (void) testArrayMacro { 25 | NSArray* a1 = [NSArray arrayWithObjects:@"valueOne", @"valueTwo", nil]; 26 | NSArray* a2 = $A(@"valueOne", @"valueTwo"); 27 | GHAssertEquals([a1 count], [a2 count], nil); 28 | GHAssertEqualStrings([a1 objectAtIndex:0], [a2 objectAtIndex:0], nil); 29 | GHAssertEqualStrings([a1 objectAtIndex:1], [a2 objectAtIndex:1], nil); 30 | } 31 | 32 | - (void) testStringMacro { 33 | NSString* s1 = [NSString stringWithFormat:@"Test %@ String %@", @"One", [NSNumber numberWithInt:1]]; 34 | NSString* s2 = $S(@"Test %@ String %@", @"One", [NSNumber numberWithInt:1]); 35 | GHAssertEqualStrings(s1, s2, nil); 36 | } 37 | 38 | - (void) testIntMacro { 39 | GHAssertEquals(42, [$I(42) intValue], nil); 40 | } 41 | 42 | - (void) testFloatMacro { 43 | GHAssertEquals([[NSNumber numberWithFloat:42.42] floatValue], [$F(42.42) floatValue], nil); 44 | } 45 | 46 | - (void) testBoolMacro { 47 | GHAssertEquals(YES, [$B(YES) boolValue], nil); 48 | } 49 | 50 | 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /Examples/CoreTest/GHLogicTests_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'CoreTest' target in the 'CoreTest' project 3 | // 4 | #import 5 | 6 | #ifndef __IPHONE_3_0 7 | #warning "This project uses features only available in iPhone SDK 3.0 and later." 8 | #endif 9 | 10 | 11 | #ifdef __OBJC__ 12 | #import 13 | #import 14 | #import 15 | #import "CoreUtils.h" 16 | #import "GHUnit.h" 17 | #import "TestHelpers.h" 18 | #import "SBJSON.h" 19 | #import "NSString+SBJSON.h" 20 | #endif 21 | -------------------------------------------------------------------------------- /Examples/CoreTest/GHUnit/GHAsyncTestCase.h: -------------------------------------------------------------------------------- 1 | // 2 | // GHAsyncTestCase.h 3 | // GHUnit 4 | // 5 | // Created by Gabriel Handford on 4/8/09. 6 | // Copyright 2009. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import "GHTestCase.h" 31 | 32 | // Some default statuses to use; Or define and use your own 33 | enum { 34 | kGHUnitWaitStatusUnknown = 0, 35 | kGHUnitWaitStatusSuccess, 36 | kGHUnitWaitStatusFailure, 37 | kGHUnitWaitStatusCancelled 38 | }; 39 | 40 | /*! 41 | Asynchronous test case with wait and notify. 42 | 43 | Handles the case of notify occuring before wait has started (if it was a synchronous call). 44 | Be sure to call prepare before the asynchronous method (otherwise an exception will raise). 45 | 46 | @code 47 | - (void)testSuccess { 48 | [self prepare]; 49 | 50 | // Do asynchronous task here 51 | [self performSelector:@selector(_succeed) withObject:nil afterDelay:0.1]; 52 | 53 | [self waitForStatus:kGHUnitWaitStatusSuccess timeout:1.0]; 54 | } 55 | 56 | - (void)_succeed { 57 | // Notice the forSelector points to the test above. This is so that 58 | // stray notifies don't error or falsely succeed other tests. 59 | [self notify:kGHUnitWaitStatusSuccess forSelector:@selector(testSuccess)]; 60 | } 61 | @endcode 62 | */ 63 | @interface GHAsyncTestCase : GHTestCase { 64 | 65 | NSInteger waitForStatus_; 66 | NSInteger notifiedStatus_; 67 | 68 | BOOL prepared_; // Whether prepared was called before waitForStatus:timeout: 69 | NSRecursiveLock *lock_; // Lock to synchronize on 70 | SEL waitSelector_; // The selector we are waiting on 71 | 72 | NSArray *_runLoopModes; // Run loop modes to run while waiting; Defaults to NSDefaultRunLoopMode, NSRunLoopCommonModes, NSConnectionReplyMode 73 | } 74 | 75 | @property (retain, nonatomic) NSArray *runLoopModes; 76 | 77 | /*! 78 | Prepare before calling the asynchronous method. 79 | */ 80 | - (void)prepare; 81 | 82 | /*! 83 | Prepare and specify the selector we will use in notify. 84 | 85 | @param selector 86 | */ 87 | - (void)prepare:(SEL)selector; 88 | 89 | /*! 90 | Wait for notification of status or timeout. 91 | 92 | Be sure to prepare before calling your asynchronous method. 93 | For example, 94 | 95 | @code 96 | - (void)testFoo { 97 | [self prepare]; 98 | // Do asynchronous task here 99 | [self waitForStatus:kGHUnitWaitStatusSuccess timeout:1.0]; 100 | } 101 | @endcode 102 | 103 | @param status kGHUnitWaitStatusSuccess, kGHUnitWaitStatusFailure or custom status 104 | @param timeout Timeout in seconds 105 | */ 106 | - (void)waitForStatus:(NSInteger)status timeout:(NSTimeInterval)timeout; 107 | 108 | // Deprecated 109 | - (void)waitFor:(NSInteger)status timeout:(NSTimeInterval)timeout; 110 | 111 | /*! 112 | Wait for timeout to occur. 113 | Fails if we did _NOT_ timeout. 114 | @param timeout 115 | */ 116 | - (void)waitForTimeout:(NSTimeInterval)timeout; 117 | 118 | /*! 119 | Notify waiting of status for test selector. 120 | @param status Status, for example, kGHUnitWaitStatusSuccess 121 | @param selector If not NULL, then will verify this selector is where we are waiting. 122 | This prevents stray asynchronous callbacks to fail a later test 123 | */ 124 | - (void)notify:(NSInteger)status forSelector:(SEL)selector; 125 | 126 | /*! 127 | Notify waiting of status for any selector. 128 | @param status Status, for example, kGHUnitWaitStatusSuccess 129 | */ 130 | - (void)notify:(NSInteger)status; 131 | 132 | @end 133 | -------------------------------------------------------------------------------- /Examples/CoreTest/GHUnit/GHTestSuite.h: -------------------------------------------------------------------------------- 1 | // 2 | // GHTestSuite.h 3 | // GHUnit 4 | // 5 | // Created by Gabriel Handford on 1/25/09. 6 | // Copyright 2009. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import "GHTestGroup.h" 31 | 32 | /*! 33 | If set, will run it as a "test filter" like the env variable TEST. 34 | */ 35 | extern NSString *GHUnitTest; 36 | 37 | 38 | /*! 39 | Test suite is an alias for test group. 40 | 41 | A test case is an instance of a test case class with test methods. 42 | A test is a id which represents a target and a selector. 43 | A test group is a collection of tests; A collection of id (GHTest or GHTestGroup). 44 | 45 | For example, if you have 2 test cases, GHTestCase1 (with some test methods) and GHTestCase2 (with some test methods), 46 | your test suite might look like: 47 | 48 | "Tests" (GHTestSuite) 49 | GHTestGroup (collection of tests from GHTestCase1) 50 | - (void)testA1 (GHTest with target GHTestCase1 + testA1) 51 | - (void)testA2 (GHTest with target GHTestCase1 + testA2) 52 | GHTestGroup (collection of tests from GHTestCase2) 53 | - (void)testB1; (GHTest with target GHTestCase2 + testB1) 54 | - (void)testB2; (GHTest with target GHTestCase2 + testB2) 55 | 56 | */ 57 | @interface GHTestSuite : GHTestGroup { } 58 | 59 | /*! 60 | Create test suite with test cases. 61 | @param name Label to give the suite 62 | @param testCases Array of init'ed test case classes 63 | @param delegate 64 | */ 65 | - (id)initWithName:(NSString *)name testCases:(NSArray *)testCases delegate:(id)delegate; 66 | 67 | /*! 68 | Creates a suite of all tests. 69 | Will load all classes that subclass from GHTestCase, SenTestCase or GTMTestCase (or register test case class). 70 | @result Suite 71 | */ 72 | + (GHTestSuite *)allTests; 73 | 74 | /*! 75 | Create suite of tests with filter. 76 | This is useful for running a single test or all tests in a single test case. 77 | 78 | For example, 79 | 'GHSlowTest' -- Runs all test method in GHSlowTest 80 | 'GHSlowTest/testSlowA -- Only runs the test method testSlowA in GHSlowTest 81 | 82 | @param testFilter Test filter 83 | @result Suite 84 | */ 85 | + (GHTestSuite *)suiteWithTestFilter:(NSString *)testFilter; 86 | 87 | /*! 88 | Create suite of tests that start with prefix. 89 | @param prefix If test case class starts with the prefix; If nil or empty string, returns all tests 90 | @param options Compare options 91 | */ 92 | + (GHTestSuite *)suiteWithPrefix:(NSString *)prefix options:(NSStringCompareOptions)options; 93 | 94 | /*! 95 | Suite for a single test/method. 96 | @param testCaseClass 97 | @param method 98 | @result Suite 99 | */ 100 | + (GHTestSuite *)suiteWithTestCaseClass:(Class)testCaseClass method:(SEL)method; 101 | 102 | /*! 103 | Return test suite based on environment (TEST=TestFoo/foo) 104 | @result Suite 105 | */ 106 | + (GHTestSuite *)suiteFromEnv; 107 | 108 | @end 109 | -------------------------------------------------------------------------------- /Examples/CoreTest/GHUnit/GHTesting.h: -------------------------------------------------------------------------------- 1 | // 2 | // GHTesting.h 3 | // GHUnit 4 | // 5 | // Created by Gabriel Handford on 1/30/09. 6 | // Copyright 2008 Gabriel Handford 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | // 31 | // Portions of this file fall under the following license, marked with: 32 | // GTM_BEGIN : GTM_END 33 | // 34 | // Copyright 2008 Google Inc. 35 | // 36 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not 37 | // use this file except in compliance with the License. You may obtain a copy 38 | // of the License at 39 | // 40 | // http://www.apache.org/licenses/LICENSE-2.0 41 | // 42 | // Unless required by applicable law or agreed to in writing, software 43 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 44 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 45 | // License for the specific language governing permissions and limitations under 46 | // the License. 47 | // 48 | 49 | extern NSString *GHUStackTraceFromException(NSException *e); 50 | 51 | // GTM_BEGIN 52 | BOOL isTestFixtureOfClass(Class aClass, Class testCaseClass); 53 | // GTM_END 54 | 55 | /*! 56 | Utility test for loading and running tests. 57 | @note Much of this is borrowed from GTM/UnitTesting. 58 | */ 59 | @interface GHTesting : NSObject { 60 | 61 | NSMutableArray/* of NSString*/ *testCaseClassNames_; 62 | 63 | } 64 | 65 | /*! 66 | The shared testing instance. 67 | */ 68 | + (GHTesting *)sharedInstance; 69 | 70 | /*! 71 | Load all test classes that we can "see". 72 | @result Array of initialized (and autoreleased) test case classes in an autoreleased array. 73 | */ 74 | - (NSArray *)loadAllTestCases; 75 | 76 | /*! 77 | Load tests from target. 78 | @result Array of id 79 | */ 80 | - (NSArray *)loadTestsFromTarget:(id)target; 81 | 82 | /*! 83 | See if class is of a registered test case class. 84 | */ 85 | - (BOOL)isTestCaseClass:(Class)aClass; 86 | 87 | /*! 88 | Register test case class. 89 | @param aClass 90 | */ 91 | - (void)registerClass:(Class)aClass; 92 | 93 | /*! 94 | Register test case class by name. 95 | @param className Class name (via NSStringFromClass(aClass) 96 | */ 97 | - (void)registerClassName:(NSString *)className; 98 | 99 | /*! 100 | Format test exception. 101 | @param exception 102 | @result Description 103 | */ 104 | + (NSString *)descriptionForException:(NSException *)exception; 105 | 106 | /*! 107 | Filename for cause of test exception. 108 | @param test 109 | @result Filename 110 | */ 111 | + (NSString *)exceptionFilenameForTest:(id)test; 112 | 113 | /*! 114 | Line number for cause of test exception. 115 | @param test 116 | @result Line number 117 | */ 118 | + (NSInteger)exceptionLineNumberForTest:(id)test; 119 | 120 | /*! 121 | Run test. 122 | @param target 123 | @param selector 124 | @param exception Exception, if set, is retained and should be released by the caller. 125 | @param interval Time to run the test 126 | @param reraiseExceptions If YES, will re-raise exceptions 127 | */ 128 | + (BOOL)runTestWithTarget:(id)target selector:(SEL)selector exception:(NSException **)exception 129 | interval:(NSTimeInterval *)interval reraiseExceptions:(BOOL)reraiseExceptions; 130 | 131 | /*! 132 | Same as normal runTest without catching exceptions. 133 | */ 134 | + (BOOL)runTestOrRaiseWithTarget:(id)target selector:(SEL)selector exception:(NSException **)exception interval:(NSTimeInterval *)interval; 135 | 136 | @end 137 | 138 | @protocol GHSenTestCase 139 | - (void)raiseAfterFailure; 140 | @end 141 | -------------------------------------------------------------------------------- /Examples/CoreTest/GHUnit/GHUNSObject+Swizzle.h: -------------------------------------------------------------------------------- 1 | // 2 | // GHNSObject+Swizzle.h 3 | // GHUnit 4 | // 5 | // Created by Gabriel Handford on 4/13/09. 6 | // Copyright 2009. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | @interface NSObject (GHUSwizzle) 31 | 32 | + (void)ghu_swizzleMethod:(SEL)original withMethod:(SEL)alternate; 33 | + (void)ghu_swizzleClassMethod:(SEL)original withClassMethod:(SEL)alternate; 34 | 35 | @end 36 | 37 | -------------------------------------------------------------------------------- /Examples/CoreTest/GHUnit/GHUnit.h: -------------------------------------------------------------------------------- 1 | // 2 | // GHUnit.h 3 | // GHUnit 4 | // 5 | // Created by Gabriel Handford on 1/19/09. 6 | // Copyright 2009. All rights reserved. 7 | // 8 | // Permission is hereby granted, free of charge, to any person 9 | // obtaining a copy of this software and associated documentation 10 | // files (the "Software"), to deal in the Software without 11 | // restriction, including without limitation the rights to use, 12 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 13 | // copies of the Software, and to permit persons to whom the 14 | // Software is furnished to do so, subject to the following 15 | // conditions: 16 | // 17 | // The above copyright notice and this permission notice shall be 18 | // included in all copies or substantial portions of the Software. 19 | // 20 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 22 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 23 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 24 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 25 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 26 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 27 | // OTHER DEALINGS IN THE SOFTWARE. 28 | // 29 | 30 | #import "GHTestCase.h" 31 | #import "GHAsyncTestCase.h" 32 | #import "GHTestSuite.h" 33 | #import "GHTestMacros.h" 34 | #import "GHTestRunner.h" 35 | 36 | #ifdef DEBUG 37 | #define GHUDebug(fmt, ...) do { \ 38 | fputs([[[NSString stringWithFormat:fmt, ##__VA_ARGS__] stringByAppendingString:@"\n"] UTF8String], stdout); \ 39 | } while(0) 40 | #else 41 | #define GHUDebug(fmt, ...) do {} while(0) 42 | #endif -------------------------------------------------------------------------------- /Examples/CoreTest/GHUnit/GHUnitIPhoneAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // GHUnitIPhoneAppDelegate.h 3 | // GHUnitIPhone 4 | // 5 | // Created by Gabriel Handford on 1/25/09. 6 | // Copyright 2009. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface GHUnitIPhoneAppDelegate : NSObject { 12 | UIWindow *window_; 13 | 14 | UINavigationController *navigationController_; 15 | } 16 | 17 | @end 18 | 19 | -------------------------------------------------------------------------------- /Examples/CoreTest/GHUnit/GHUnitIPhoneTestMain.m: -------------------------------------------------------------------------------- 1 | // 2 | // GHUnitIPhoneTestMain.m 3 | // GHUnitIPhone 4 | // 5 | // Created by Gabriel Handford on 1/25/09. 6 | // Copyright 2009. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | #import "GHUnit.h" 12 | #import "GHTesting.h" 13 | 14 | // Default exception handler 15 | void exceptionHandler(NSException *exception) { 16 | NSLog(@"%@\n%@", [exception reason], GHUStackTraceFromException(exception)); 17 | } 18 | 19 | int main(int argc, char *argv[]) { 20 | 21 | /*! 22 | For debugging: 23 | Go into the "Get Info" contextual menu of your (test) executable (inside the "Executables" group in the left panel of XCode). 24 | Then go in the "Arguments" tab. You can add the following environment variables: 25 | 26 | Default: Set to: 27 | NSDebugEnabled NO "YES" 28 | NSZombieEnabled NO "YES" 29 | NSDeallocateZombies NO "YES" 30 | NSHangOnUncaughtException NO "YES" 31 | 32 | NSEnableAutoreleasePool YES "NO" 33 | NSAutoreleaseFreedObjectCheckEnabled NO "YES" 34 | NSAutoreleaseHighWaterMark 0 non-negative integer 35 | NSAutoreleaseHighWaterResolution 0 non-negative integer 36 | 37 | For info on these varaiables see NSDebug.h; http://theshadow.uw.hu/iPhoneSDKdoc/Foundation.framework/NSDebug.h.html 38 | 39 | For malloc debugging see: http://developer.apple.com/mac/library/documentation/Performance/Conceptual/ManagingMemory/Articles/MallocDebug.html 40 | */ 41 | 42 | NSSetUncaughtExceptionHandler(&exceptionHandler); 43 | 44 | NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; 45 | 46 | // Register any special test case classes 47 | //[[GHTesting sharedInstance] registerClassName:@"GHSpecialTestCase"]; 48 | 49 | int retVal = 0; 50 | // If GHUNIT_CLI is set we are using the command line interface and run the tests 51 | // Otherwise load the GUI app 52 | if (getenv("GHUNIT_CLI")) { 53 | retVal = [GHTestRunner run]; 54 | } else { 55 | retVal = UIApplicationMain(argc, argv, nil, @"GHUnitIPhoneAppDelegate"); 56 | } 57 | [pool release]; 58 | return retVal; 59 | } 60 | -------------------------------------------------------------------------------- /Examples/CoreTest/GHUnit/Makefile: -------------------------------------------------------------------------------- 1 | 2 | TEST_TARGET=Tests 3 | SDK=iphonesimulator3.0 4 | COMMAND=xcodebuild 5 | 6 | default: 7 | # Set default make action here 8 | 9 | # If you need to clean a specific target/configuration: $(COMMAND) -target $(TARGET) -configuration DebugOrRelease -sdk $(SDK) clean 10 | clean: 11 | -rm -rf build/* 12 | 13 | test: 14 | GHUNIT_CLI=1 $(COMMAND) -target $(TEST_TARGET) -configuration Debug -sdk $(SDK) build 15 | 16 | -------------------------------------------------------------------------------- /Examples/CoreTest/GHUnit/NSException+GHTestFailureExceptions.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSException+GHTestFailureExceptions.h 3 | // 4 | // Created by Johannes Rudolph on 23.09.09. 5 | // Copyright 2009. All rights reserved. 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | // 30 | // Portions of this file fall under the following license, marked with: 31 | // GTM_BEGIN : GTM_END 32 | // 33 | // Copyright 2008 Google Inc. 34 | // 35 | // Licensed under the Apache License, Version 2.0 (the "License"); you may not 36 | // use this file except in compliance with the License. You may obtain a copy 37 | // of the License at 38 | // 39 | // http://www.apache.org/licenses/LICENSE-2.0 40 | // 41 | // Unless required by applicable law or agreed to in writing, software 42 | // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT 43 | // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the 44 | // License for the specific language governing permissions and limitations under 45 | // the License. 46 | // 47 | 48 | extern NSString *const GHTestFilenameKey; 49 | extern NSString *const GHTestLineNumberKey; 50 | extern NSString *const GHTestFailureException; 51 | 52 | 53 | // GTM_BEGIN 54 | 55 | #import 56 | 57 | @interface NSException (GHUTestFailureExceptions) 58 | + (NSException *)ghu_failureInFile:(NSString *)filename 59 | atLine:(int)lineNumber 60 | withDescription:(NSString *)formatString, ...; 61 | + (NSException *)ghu_failureInCondition:(NSString *)condition 62 | isTrue:(BOOL)isTrue 63 | inFile:(NSString *)filename 64 | atLine:(int)lineNumber 65 | withDescription:(NSString *)formatString, ...; 66 | + (NSException *)ghu_failureInEqualityBetweenObject:(id)left 67 | andObject:(id)right 68 | inFile:(NSString *)filename 69 | atLine:(int)lineNumber 70 | withDescription:(NSString *)formatString, ...; 71 | + (NSException *)ghu_failureInEqualityBetweenValue:(NSValue *)left 72 | andValue:(NSValue *)right 73 | withAccuracy:(NSValue *)accuracy 74 | inFile:(NSString *)filename 75 | atLine:(int) ineNumber 76 | withDescription:(NSString *)formatString, ...; 77 | + (NSException *)ghu_failureInRaise:(NSString *)expression 78 | inFile:(NSString *)filename 79 | atLine:(int)lineNumber 80 | withDescription:(NSString *)formatString, ...; 81 | + (NSException *)ghu_failureInRaise:(NSString *)expression 82 | exception:(NSException *)exception 83 | inFile:(NSString *)filename 84 | atLine:(int)lineNumber 85 | withDescription:(NSString *)formatString, ...; 86 | @end 87 | 88 | // GTM_END -------------------------------------------------------------------------------- /Examples/CoreTest/GHUnit/NSValue+GHValueFormatter.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSValue+GHValueFormatter.h 3 | // 4 | // Created by Johannes Rudolph on 23.9.2009. 5 | // Copyright 2009. All rights reserved. 6 | // 7 | // Permission is hereby granted, free of charge, to any person 8 | // obtaining a copy of this software and associated documentation 9 | // files (the "Software"), to deal in the Software without 10 | // restriction, including without limitation the rights to use, 11 | // copy, modify, merge, publish, distribute, sublicense, and/or sell 12 | // copies of the Software, and to permit persons to whom the 13 | // Software is furnished to do so, subject to the following 14 | // conditions: 15 | // 16 | // The above copyright notice and this permission notice shall be 17 | // included in all copies or substantial portions of the Software. 18 | // 19 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 | // EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES 21 | // OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 22 | // NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 23 | // HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 24 | // WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 25 | // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 26 | // OTHER DEALINGS IN THE SOFTWARE. 27 | // 28 | 29 | // 30 | // Portions of this file fall under the following license, marked with 31 | // SENTE_BEGIN - SENTE_END 32 | // 33 | // Copyright (c) 1997-2005, Sen:te (Sente SA). All rights reserved. 34 | // 35 | // Use of this source code is governed by the following license: 36 | // 37 | // Redistribution and use in source and binary forms, with or without modification, 38 | // are permitted provided that the following conditions are met: 39 | // 40 | // (1) Redistributions of source code must retain the above copyright notice, 41 | // this list of conditions and the following disclaimer. 42 | // 43 | // (2) Redistributions in binary form must reproduce the above copyright notice, 44 | // this list of conditions and the following disclaimer in the documentation 45 | // and/or other materials provided with the distribution. 46 | // 47 | // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS ``AS IS'' 48 | // AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 49 | // WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 50 | // IN NO EVENT SHALL Sente SA OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 51 | // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT 52 | // OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 53 | // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 54 | // OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 55 | // EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 56 | // 57 | // Note: this license is equivalent to the FreeBSD license. 58 | // 59 | // This notice may not be removed from this file. 60 | 61 | #import 62 | 63 | // SENTE_BEGIN 64 | @interface NSValue (GHValueFormatter) 65 | - (NSString *)ghu_contentDescription; 66 | @end 67 | // SENTE_END 68 | -------------------------------------------------------------------------------- /Examples/CoreTest/GHUnit/RunTests.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # If we aren't running from the command line, then exit 4 | if [ "$GHUNIT_CLI" != "1" ]; then 5 | exit 0 6 | fi 7 | 8 | export DYLD_ROOT_PATH="$SDKROOT" 9 | export DYLD_FRAMEWORK_PATH="$CONFIGURATION_BUILD_DIR" 10 | export IPHONE_SIMULATOR_ROOT="$SDKROOT" 11 | 12 | export MallocScribble=YES 13 | export MallocPreScribble=YES 14 | export MallocGuardEdges=YES 15 | export MallocStackLogging=YES 16 | export MallocStackLoggingNoCompact=YES 17 | export NSAutoreleaseFreedObjectCheckEnabled=YES 18 | 19 | export CFZombieLevel=3 20 | export NSZombieEnabled=YES 21 | 22 | "$TARGET_BUILD_DIR/$EXECUTABLE_PATH" -RegisterForSystemEvents 23 | RETVAL=$? 24 | 25 | exit $RETVAL 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /Examples/CoreTest/GHUnit/libGHUnitIPhone3_0.a: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikelaurence/CoreResource/9948473ed3ec33ab0c80d7ffc96cbb9e7cd338ad/Examples/CoreTest/GHUnit/libGHUnitIPhone3_0.a -------------------------------------------------------------------------------- /Examples/CoreTest/MiscBenchmarks.m: -------------------------------------------------------------------------------- 1 | // 2 | // MiscBenchmarks.m 3 | // CoreTest 4 | // 5 | // Created by Mike Laurence on 3/11/10. 6 | // Copyright 2010 Mike Laurence. All rights reserved. 7 | // 8 | 9 | 10 | #import "CoreResourceTestCase.h" 11 | 12 | @interface MiscBenchmarks : CoreResourceTestCase { 13 | // Cached pointers 14 | Artist* artist; 15 | NSString* value; 16 | NSString* readKey; 17 | NSString* writeKey; 18 | SEL readSel, writeSel; 19 | } 20 | @end 21 | 22 | @implementation MiscBenchmarks 23 | 24 | #define ITERATE for (int i = 0; i < 600000; i++) 25 | 26 | - (void) setUp { 27 | [super setUp]; 28 | artist = [[self loadArtist:0] retain]; 29 | readKey = [@"name" retain]; 30 | readSel = @selector(name); 31 | writeKey = [@"setName" retain]; 32 | writeSel = @selector(setName:); 33 | } 34 | 35 | - (void) testReadsUsingDynamicGetters { 36 | ITERATE value = artist.name; 37 | } 38 | 39 | - (void) testReadsUsingKVC { 40 | ITERATE value = [artist valueForKey:readKey]; 41 | } 42 | 43 | - (void) testReadsUsingPrimitiveKVC { 44 | ITERATE value = [artist primitiveValueForKey:readKey]; 45 | } 46 | 47 | - (void) testReadsUsingSelector { 48 | ITERATE value = [artist performSelector:readSel]; 49 | } 50 | 51 | - (void) testReadsUsingConvertedSelector { 52 | ITERATE value = [artist performSelector:NSSelectorFromString(readKey)]; 53 | } 54 | 55 | - (void) testWritesUsingDynamicSetters { 56 | ITERATE artist.name = @"Schpoon"; 57 | } 58 | 59 | - (void) testWritesUsingKVC { 60 | ITERATE [artist setValue:@"Schpoon" forKey:@"name"]; 61 | } 62 | 63 | - (void) testWritesUsingPerformSelector { 64 | ITERATE value = [artist performSelector:writeSel withObject:@"Schpoon"]; 65 | } 66 | 67 | @end 68 | -------------------------------------------------------------------------------- /Examples/CoreTest/NSArrayCategoryTests.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSArrayCategoryTests.m 3 | // CoreTest 4 | // 5 | // Created by Mike Laurence on 3/11/10. 6 | // Copyright 2010 Mike Laurence. All rights reserved. 7 | // 8 | 9 | #import "CoreResourceTestCase.h" 10 | #import "NSArray+Core.h" 11 | 12 | 13 | @interface NSArrayCategoryTests : CoreResourceTestCase {} 14 | @end 15 | 16 | @implementation NSArrayCategoryTests 17 | 18 | - (void) testSortedArrayByKey { 19 | NSArray* unsorted = $A($D(@"one", @"name"), $D(@"two", @"name"), $D(@"three", @"name"), $D(@"four", @"name")); 20 | 21 | NSArray* ascending = [unsorted sortedArrayUsingKey:@"name" ascending:YES]; 22 | GHAssertEqualStrings([[ascending objectAtIndex:0] objectForKey:@"name"], @"four", nil); 23 | GHAssertEqualStrings([[ascending objectAtIndex:1] objectForKey:@"name"], @"one", nil); 24 | GHAssertEqualStrings([[ascending objectAtIndex:2] objectForKey:@"name"], @"three", nil); 25 | GHAssertEqualStrings([[ascending objectAtIndex:3] objectForKey:@"name"], @"two", nil); 26 | 27 | NSArray* descending = [unsorted sortedArrayUsingKey:@"name" ascending:NO]; 28 | GHAssertEqualStrings([[descending objectAtIndex:0] objectForKey:@"name"], @"two", nil); 29 | GHAssertEqualStrings([[descending objectAtIndex:1] objectForKey:@"name"], @"three", nil); 30 | GHAssertEqualStrings([[descending objectAtIndex:2] objectForKey:@"name"], @"one", nil); 31 | GHAssertEqualStrings([[descending objectAtIndex:3] objectForKey:@"name"], @"four", nil); 32 | } 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /Examples/CoreTest/RunTests.sh: -------------------------------------------------------------------------------- 1 | GHUNIT_CLI=1 xcodebuild -target CoreTest -configuration Debug -sdk iphonesimulator3.1 build -------------------------------------------------------------------------------- /Examples/CoreTest/TestHelpers.h: -------------------------------------------------------------------------------- 1 | // 2 | // TestHelpers.h 3 | // CoreTest 4 | // 5 | // Created by Mike Laurence on 1/15/10. 6 | // Copyright 2010 Mike Laurence. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | @interface TestHelpers : NSObject { 13 | } 14 | 15 | void SwizzleMethod(Class destClass, SEL destSelector, Class origClass, SEL origSelector, BOOL isInstanceMethod); 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /Examples/CoreTest/TestHelpers.m: -------------------------------------------------------------------------------- 1 | // 2 | // TestHelpers.m 3 | // CoreTest 4 | // 5 | // Created by Mike Laurence on 1/15/10. 6 | // Copyright 2010 Mike Laurence. All rights reserved. 7 | // 8 | 9 | #import "TestHelpers.h" 10 | #import 11 | 12 | 13 | @implementation TestHelpers 14 | 15 | void SwizzleMethod(Class destClass, SEL destSelector, Class origClass, SEL origSelector, BOOL isInstanceMethod) { 16 | Method dMethod = class_getClassMethod(isInstanceMethod ? destClass : destClass->isa, destSelector); 17 | Method oMethod = class_getClassMethod(isInstanceMethod ? origClass : origClass->isa, origSelector); 18 | if(!class_addMethod(isInstanceMethod ? destClass : destClass->isa, destSelector, method_getImplementation(oMethod), method_getTypeEncoding(oMethod))) 19 | method_exchangeImplementations(dMethod, oMethod); 20 | } 21 | 22 | @end 23 | -------------------------------------------------------------------------------- /Examples/CoreTest/TestScript.sh: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | 3 | # If we aren't running from the command line, then exit 4 | if [ "$GHUNIT_CLI" != "1" ]; then 5 | exit 0 6 | fi 7 | 8 | export DYLD_ROOT_PATH="$SDKROOT" 9 | export DYLD_FRAMEWORK_PATH="$CONFIGURATION_BUILD_DIR" 10 | export IPHONE_SIMULATOR_ROOT="$SDKROOT" 11 | 12 | export MallocScribble=YES 13 | export MallocPreScribble=YES 14 | export MallocGuardEdges=YES 15 | export MallocStackLogging=YES 16 | export MallocStackLoggingNoCompact=YES 17 | export NSAutoreleaseFreedObjectCheckEnabled=YES 18 | 19 | export CFZombieLevel=3 20 | export NSZombieEnabled=YES 21 | 22 | "$TARGET_BUILD_DIR/$EXECUTABLE_PATH" -RegisterForSystemEvents 23 | RETVAL=$? 24 | 25 | exit $RETVAL 26 | 27 | 28 | 29 | -------------------------------------------------------------------------------- /Examples/CoreTest/artists.0.alternate-field-names.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": 0, 3 | "theName": "Peter Gabriel", 4 | "theSummary": "Peter Brian Gabriel is an English musician and songwriter.", 5 | "theDetail": "Peter Brian Gabriel (born 13 February 1950) is an English musician and songwriter who rose to fame as the lead vocalist and flautist of the progressive rock group Genesis. After leaving Genesis, Gabriel went on to a successful solo career. More recently he has focused on producing and promoting world music and pioneering digital distribution methods for music. He has also been involved in various humanitarian efforts. Gabriel was awarded the Polar Music Prize in 2009.", 6 | "updatedAt": "2009-12-31T04:41:54Z" 7 | } -------------------------------------------------------------------------------- /Examples/CoreTest/artists.0.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": 0, 3 | "name": "Peter Gabriel", 4 | "summary": "Peter Brian Gabriel is an English musician and songwriter.", 5 | "detail": "Peter Brian Gabriel (born 13 February 1950) is an English musician and songwriter who rose to fame as the lead vocalist and flautist of the progressive rock group Genesis. After leaving Genesis, Gabriel went on to a successful solo career. More recently he has focused on producing and promoting world music and pioneering digital distribution methods for music. He has also been involved in various humanitarian efforts. Gabriel was awarded the Polar Music Prize in 2009.", 6 | "updatedAt": "2009-12-31T04:41:54Z" 7 | } -------------------------------------------------------------------------------- /Examples/CoreTest/artists.0.update.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": 0, 3 | "name": "Peter B. Gabriel", 4 | "summary": "Peter Brian Gabriel is a musician and songwriter.", 5 | "detail": "Peter Brian Gabriel (born 13 February 1950) is an English musician and songwriter. He's quite good.", 6 | "updatedAt": "2009-12-31T08:50:54Z" 7 | } -------------------------------------------------------------------------------- /Examples/CoreTest/artists.1.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": 1, 3 | "name": "Spoon", 4 | "summary": "Spoon is an American indie rock band from Austin, Texas.", 5 | "detail": "Spoon is an American indie rock band from Austin, Texas. The band is composed of Britt Daniel (vocals, guitar); Jim Eno (drums); Rob Pope (bass) and Eric Harvey (keyboard, guitar, percussion, backing vocals).", 6 | "updatedAt": "2009-12-08T09:11:23Z", 7 | "songs": [ 8 | { 9 | "id": 1, 10 | "name": "Don't Make Me a Target" 11 | }, 12 | { 13 | "id": 2, 14 | "name": "You Got Yr. Cherry Bomb" 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /Examples/CoreTest/artists.2.json: -------------------------------------------------------------------------------- 1 | { 2 | "id": 2, 3 | "name": "Phoenix", 4 | "summary": "Phoenix is a Grammy nominated French alternative rock band.", 5 | "detail": "Phoenix is a Grammy nominated French alternative rock band started during their childhood by Thomas Mars, Deck D'Arcy, Christian Mazzalai and Laurent Brancowitz in the suburb of Versailles, in the same culture that produced late-'90s bands such as Air and Daft Punk.", 6 | "updatedAt": "2009-12-26T11:00:00Z", 7 | "songs": [ 8 | { 9 | "id": 3, 10 | "name": "Lisztomania" 11 | }, 12 | { 13 | "id": 4, 14 | "name": "1901" 15 | } 16 | ] 17 | } -------------------------------------------------------------------------------- /Examples/CoreTest/artists.json: -------------------------------------------------------------------------------- 1 | [ 2 | { 3 | "id": 0, 4 | "name": "Peter Gabriel", 5 | "summary": "Peter Brian Gabriel is an English musician and songwriter.", 6 | "detail": "Peter Brian Gabriel (born 13 February 1950) is an English musician and songwriter who rose to fame as the lead vocalist and flautist of the progressive rock group Genesis. After leaving Genesis, Gabriel went on to a successful solo career. More recently he has focused on producing and promoting world music and pioneering digital distribution methods for music. He has also been involved in various humanitarian efforts. Gabriel was awarded the Polar Music Prize in 2009.", 7 | "updatedAt": "2009-12-31T04:41:54Z" 8 | }, 9 | { 10 | "id": 1, 11 | "name": "Spoon", 12 | "summary": "Spoon is an American indie rock band from Austin, Texas.", 13 | "detail": "Spoon is an American indie rock band from Austin, Texas. The band is composed of Britt Daniel (vocals, guitar); Jim Eno (drums); Rob Pope (bass) and Eric Harvey (keyboard, guitar, percussion, backing vocals).", 14 | "updatedAt": "2009-12-08T09:11:23Z", 15 | "songs": [ 16 | { 17 | "id": 1, 18 | "name": "Don't Make Me a Target" 19 | }, 20 | { 21 | "id": 2, 22 | "name": "You Got Yr. Cherry Bomb" 23 | } 24 | ] 25 | }, 26 | { 27 | "id": 2, 28 | "name": "Phoenix", 29 | "summary": "Phoenix is a Grammy nominated French alternative rock band.", 30 | "detail": "Phoenix is a Grammy nominated French alternative rock band started during their childhood by Thomas Mars, Deck D'Arcy, Christian Mazzalai and Laurent Brancowitz in the suburb of Versailles, in the same culture that produced late-'90s bands such as Air and Daft Punk.", 31 | "updatedAt": "2009-12-26T11:00:00Z", 32 | "songs": [ 33 | { 34 | "id": 3, 35 | "name": "Lisztomania" 36 | }, 37 | { 38 | "id": 4, 39 | "name": "1901" 40 | } 41 | ] 42 | } 43 | ] -------------------------------------------------------------------------------- /Examples/CoreTest/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // CoreTest 4 | // 5 | // Created by Mike Laurence on 1/14/10. 6 | // Copyright Punkbot LLC 2010. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, char *argv[]) { 12 | 13 | NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 14 | int retVal = UIApplicationMain(argc, argv, nil, nil); 15 | [pool release]; 16 | return retVal; 17 | } 18 | -------------------------------------------------------------------------------- /Examples/LighthouseClient/Classes/LighthouseClientAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // LighthouseClientAppDelegate.h 3 | // LighthouseClient 4 | // 5 | // Created by Mike Laurence on 3/6/10. 6 | // Copyright Punkbot LLC 2010. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CoreManager.h" 11 | 12 | 13 | @interface LighthouseClientAppDelegate : NSObject { 14 | CoreManager *coreManager; 15 | 16 | UIWindow *window; 17 | UIViewController *mainViewController; 18 | } 19 | 20 | @property (nonatomic, retain) CoreManager *coreManager; 21 | 22 | @property (nonatomic, retain) IBOutlet UIWindow *window; 23 | @property (nonatomic, retain) IBOutlet UIViewController *mainViewController; 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /Examples/LighthouseClient/Classes/LighthouseClientAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // LighthouseClientAppDelegate.m 3 | // LighthouseClient 4 | // 5 | // Created by Mike Laurence on 3/6/10. 6 | // Copyright Punkbot LLC 2010. All rights reserved. 7 | // 8 | 9 | #import "LighthouseClientAppDelegate.h" 10 | #import "Ticket.h" 11 | 12 | 13 | @implementation LighthouseClientAppDelegate 14 | 15 | @synthesize coreManager; 16 | @synthesize window; 17 | @synthesize mainViewController; 18 | 19 | 20 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary*)launchOptions { 21 | 22 | // Initialize Core Manager 23 | self.coreManager = [[[CoreManager alloc] init] autorelease]; 24 | coreManager.logLevel = 1; 25 | coreManager.remoteSiteURL = @"http://coreresource.lighthouseapp.com"; 26 | 27 | [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleBlackOpaque]; 28 | 29 | // Add the tab bar controller's current view as a subview of the window 30 | [window addSubview:mainViewController.view]; 31 | [window makeKeyAndVisible]; 32 | 33 | // Send off request to get tickets 34 | [Ticket findAllRemote]; 35 | 36 | return YES; 37 | } 38 | 39 | - (void) applicationWillTerminate:(UIApplication *)application { 40 | [coreManager save]; 41 | } 42 | 43 | 44 | 45 | #pragma mark - 46 | #pragma mark Lifecycle End 47 | 48 | - (void)dealloc { 49 | [coreManager release]; 50 | [mainViewController release]; 51 | [window release]; 52 | [super dealloc]; 53 | } 54 | 55 | @end 56 | 57 | -------------------------------------------------------------------------------- /Examples/LighthouseClient/Classes/LighthouseResource.h: -------------------------------------------------------------------------------- 1 | // 2 | // LighthouseResource.h 3 | // LighthouseClient 4 | // 5 | // Created by Mike Laurence on 3/6/10. 6 | // Copyright 2010 Punkbot LLC. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CoreResource.h" 11 | 12 | 13 | @interface LighthouseResource : CoreResource { 14 | 15 | } 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /Examples/LighthouseClient/Classes/LighthouseResource.m: -------------------------------------------------------------------------------- 1 | // 2 | // LighthouseResource.m 3 | // LighthouseClient 4 | // 5 | // Created by Mike Laurence on 3/6/10. 6 | // Copyright 2010 Punkbot LLC. All rights reserved. 7 | // 8 | 9 | #import "LighthouseResource.h" 10 | #import "NSString+InflectionSupport.h" 11 | 12 | 13 | @implementation LighthouseResource 14 | 15 | + (NSString*) localNameForRemoteField:(NSString*)field { 16 | return [field camelize]; 17 | } 18 | 19 | + (NSString*) remoteNameForLocalField:(NSString*)field { 20 | return [field deCamelizeWith:@"_"]; 21 | } 22 | 23 | // Remove nesting from JSON response 24 | + (NSArray*) dataCollectionFromDeserializedCollection:(id)deserializedCollection { 25 | 26 | NSArray* collectionArray = [[[deserializedCollection objectAtIndex:0] allValues] objectAtIndex:0]; 27 | 28 | NSMutableArray* array = [NSMutableArray arrayWithCapacity:[collectionArray count]]; 29 | for (NSDictionary* dict in collectionArray) 30 | [array addObject:[[dict allValues] objectAtIndex:0]]; 31 | 32 | return array; 33 | } 34 | 35 | @end 36 | -------------------------------------------------------------------------------- /Examples/LighthouseClient/Classes/Ticket.h: -------------------------------------------------------------------------------- 1 | // 2 | // Ticket.h 3 | // LighthouseClient 4 | // 5 | // Created by Mike Laurence on 3/6/10. 6 | // Copyright 2010 Punkbot LLC. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "LighthouseResource.h" 11 | 12 | 13 | @interface Ticket : LighthouseResource { 14 | } 15 | 16 | @property (nonatomic, retain) NSString * assignedUserName; 17 | @property (nonatomic, retain) NSNumber * closed; 18 | @property (nonatomic, retain) NSDate * createdAt; 19 | @property (nonatomic, retain) NSString * creatorName; 20 | @property (nonatomic, retain) NSString * latestBody; 21 | @property (nonatomic, retain) NSNumber * priority; 22 | @property (nonatomic, retain) NSNumber * number; 23 | @property (nonatomic, retain) NSString * permalink; 24 | @property (nonatomic, retain) NSString * title; 25 | @property (nonatomic, retain) NSDate * updatedAt; 26 | @property (nonatomic, retain) NSString * url; 27 | 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /Examples/LighthouseClient/Classes/Ticket.m: -------------------------------------------------------------------------------- 1 | // 2 | // Ticket.m 3 | // LighthouseClient 4 | // 5 | // Created by Mike Laurence on 3/6/10. 6 | // Copyright 2010 Punkbot LLC. All rights reserved. 7 | // 8 | 9 | #import "Ticket.h" 10 | 11 | 12 | @implementation Ticket 13 | 14 | @dynamic assignedUserName; 15 | @dynamic closed; 16 | @dynamic createdAt; 17 | @dynamic creatorName; 18 | @dynamic latestBody; 19 | @dynamic priority; 20 | @dynamic number; 21 | @dynamic permalink; 22 | @dynamic title; 23 | @dynamic updatedAt; 24 | @dynamic url; 25 | 26 | + (NSString*) localIdField { 27 | return @"number"; 28 | } 29 | 30 | + (NSString*) remoteIdField { 31 | return @"number"; 32 | } 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /Examples/LighthouseClient/Classes/TicketController.h: -------------------------------------------------------------------------------- 1 | // 2 | // TicketController.h 3 | // LighthouseClient 4 | // 5 | // Created by Mike Laurence on 3/6/10. 6 | // Copyright 2010 Punkbot LLC. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "Ticket.h" 11 | 12 | 13 | @interface TicketController : UIViewController { 14 | Ticket *ticket; 15 | NSDateFormatter *dateFormatter; 16 | UIToolbar *toolbar; 17 | } 18 | 19 | @property (nonatomic, retain) Ticket *ticket; 20 | 21 | - (UITableView*) tableView; 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /Examples/LighthouseClient/Classes/TicketsController.h: -------------------------------------------------------------------------------- 1 | // 2 | // TicketsController.h 3 | // LighthouseClient 4 | // 5 | // Created by Mike Laurence on 3/6/10. 6 | // Copyright Punkbot LLC 2010. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CoreTableController.h" 11 | 12 | 13 | @interface TicketsController : CoreTableController { 14 | } 15 | 16 | - (IBAction) refresh; 17 | 18 | @end 19 | -------------------------------------------------------------------------------- /Examples/LighthouseClient/Classes/TicketsController.m: -------------------------------------------------------------------------------- 1 | // 2 | // TicketsController.m 3 | // LighthouseClient 4 | // 5 | // Created by Mike Laurence on 3/6/10. 6 | // Copyright Punkbot LLC 2010. All rights reserved. 7 | // 8 | 9 | #import "TicketsController.h" 10 | #import "TicketController.h" 11 | #import "DynamicCell.h" 12 | 13 | 14 | @implementation TicketsController 15 | 16 | static float defaultFontSize = 15.0; 17 | 18 | - (void) viewWillAppear:(BOOL)animated { 19 | [super viewWillAppear:animated]; 20 | 21 | // Use results controller to fetch local data. The table will automatically be reloaded if the underlying data changes 22 | // (e.g., via an influx of remote data.) 23 | [[self coreResultsController] fetch:$D(@"priority ASC", @"$sort", $B(FALSE), @"closed")]; 24 | [[self tableView] reloadData]; 25 | } 26 | 27 | - (IBAction) refresh { 28 | [Ticket findAllRemote]; 29 | } 30 | 31 | 32 | #pragma mark - 33 | #pragma mark Core table controller methods 34 | 35 | - (Class) model { 36 | // Configure CoreTableController to use *Ticket* as its resource class 37 | return [Ticket class]; 38 | } 39 | 40 | 41 | #pragma mark - 42 | #pragma mark UITableView Data Source & Delegate 43 | 44 | - (UITableViewCell*) tableView:(UITableView *)tableView resultCellForRowAtIndexPath:(NSIndexPath *)indexPath { 45 | 46 | // Get resource at this index path 47 | Ticket *ticket = (Ticket*)[self resourceAtIndexPath:indexPath]; 48 | 49 | // Dequeue or create DynamicCell 50 | DynamicCell *cell = (DynamicCell*)[tableView dequeueReusableCellWithIdentifier:@"TicketsCell"]; 51 | if (cell == nil) { 52 | cell = [DynamicCell cellWithReuseIdentifier:@"TicketsCell"]; 53 | cell.defaultFont = [UIFont systemFontOfSize:defaultFontSize]; 54 | cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator; 55 | } 56 | 57 | // Reset the DynamicCell (recycles all current views) 58 | [cell reset]; 59 | 60 | // Add priority label 61 | UILabel* priorityLabel = [cell addLabelWithText:[ticket.priority stringValue] 62 | andFont:[UIFont boldSystemFontOfSize:defaultFontSize * 3]]; 63 | priorityLabel.textColor = [UIColor orangeColor]; 64 | 65 | // Add title label 66 | [cell addLabelWithText:ticket.title andFont:[UIFont boldSystemFontOfSize:defaultFontSize] onNewLine:NO]; 67 | 68 | // Add additional user labels 69 | UILabel *userLabel = [cell addLabelWithText:[NSString stringWithFormat:@"Assigned to %@", ticket.assignedUserName]]; 70 | userLabel.textColor = [UIColor grayColor]; 71 | 72 | // Prepare the DynamicCell (lays out all added subviews) and return 73 | [cell prepare]; 74 | return cell; 75 | } 76 | 77 | - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { 78 | if (!self.splitViewController) 79 | [tableView deselectRowAtIndexPath:indexPath animated:YES]; 80 | 81 | // Get resource at this index path 82 | Ticket *ticket = (Ticket*)[self resourceAtIndexPath:indexPath]; 83 | 84 | // Set up TicketController for viewing the details of an individual ticket 85 | TicketController *ticketController = nil; 86 | if (self.splitViewController) 87 | ticketController = [self.splitViewController.viewControllers objectAtIndex:1]; 88 | else 89 | ticketController = [[[TicketController alloc] initWithNibName:nil bundle:nil] autorelease]; 90 | ticketController.ticket = ticket; 91 | ticketController.title = [NSString stringWithFormat:@"Ticket #%@", ticket.number]; 92 | 93 | // Show the controller (iPhone => navigation stack, iPad => update splitView's second view) 94 | if (self.splitViewController) 95 | [[ticketController tableView] reloadData]; 96 | else 97 | [self.navigationController pushViewController:ticketController animated:YES]; 98 | } 99 | 100 | 101 | #pragma mark - 102 | #pragma mark UIViewController 103 | 104 | - (BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation { 105 | return YES; 106 | } 107 | 108 | 109 | 110 | @end 111 | -------------------------------------------------------------------------------- /Examples/LighthouseClient/Icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikelaurence/CoreResource/9948473ed3ec33ab0c80d7ffc96cbb9e7cd338ad/Examples/LighthouseClient/Icon.png -------------------------------------------------------------------------------- /Examples/LighthouseClient/LighthouseClient-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | UISupportedInterfaceOrientations~ipad 6 | 7 | UIInterfaceOrientationPortrait 8 | UIInterfaceOrientationPortraitUpsideDown 9 | UIInterfaceOrientationLandscapeLeft 10 | UIInterfaceOrientationLandscapeRight 11 | 12 | CFBundleDevelopmentRegion 13 | English 14 | CFBundleDisplayName 15 | ${PRODUCT_NAME} 16 | CFBundleExecutable 17 | ${EXECUTABLE_NAME} 18 | CFBundleIconFile 19 | Icon.png 20 | CFBundleIdentifier 21 | com.punkbot.${PRODUCT_NAME:rfc1034identifier} 22 | CFBundleInfoDictionaryVersion 23 | 6.0 24 | CFBundleName 25 | ${PRODUCT_NAME} 26 | CFBundlePackageType 27 | APPL 28 | CFBundleSignature 29 | ???? 30 | CFBundleVersion 31 | 1.0 32 | LSRequiresIPhoneOS 33 | 34 | NSMainNibFile 35 | MainWindow 36 | NSMainNibFile~ipad 37 | MainWindow-iPad 38 | 39 | 40 | -------------------------------------------------------------------------------- /Examples/LighthouseClient/LighthouseClient_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'LighthouseClient' target in the 'LighthouseClient' project 3 | // 4 | 5 | #ifdef __OBJC__ 6 | #import 7 | #import 8 | #import 9 | #import "CoreUtils.h" 10 | #endif 11 | -------------------------------------------------------------------------------- /Examples/LighthouseClient/images/icon-tickets.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikelaurence/CoreResource/9948473ed3ec33ab0c80d7ffc96cbb9e7cd338ad/Examples/LighthouseClient/images/icon-tickets.png -------------------------------------------------------------------------------- /Examples/LighthouseClient/lighthouse.xcdatamodel/elements: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikelaurence/CoreResource/9948473ed3ec33ab0c80d7ffc96cbb9e7cd338ad/Examples/LighthouseClient/lighthouse.xcdatamodel/elements -------------------------------------------------------------------------------- /Examples/LighthouseClient/lighthouse.xcdatamodel/layout: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikelaurence/CoreResource/9948473ed3ec33ab0c80d7ffc96cbb9e7cd338ad/Examples/LighthouseClient/lighthouse.xcdatamodel/layout -------------------------------------------------------------------------------- /Examples/LighthouseClient/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // LighthouseClient 4 | // 5 | // Created by Mike Laurence on 3/6/10. 6 | // Copyright Punkbot LLC 2010. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, char *argv[]) { 12 | NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 13 | int retVal = UIApplicationMain(argc, argv, nil, nil); 14 | [pool release]; 15 | return retVal; 16 | } 17 | 18 | -------------------------------------------------------------------------------- /Examples/TwitterClient/Classes/Status.h: -------------------------------------------------------------------------------- 1 | // 2 | // Status.h 3 | // TwitterClient 4 | // 5 | // Created by Mike Laurence on 2/9/10. 6 | // Copyright 2010 Mike Laurence. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "TwitterModel.h" 11 | 12 | @class User; 13 | 14 | @interface Status : TwitterModel { 15 | } 16 | 17 | @property (nonatomic, retain) NSDate *createdAt; 18 | @property (nonatomic, retain) NSNumber *resourceId; 19 | @property (nonatomic, retain) NSString *text; 20 | @property (nonatomic, retain) User *user; 21 | 22 | @end -------------------------------------------------------------------------------- /Examples/TwitterClient/Classes/Status.m: -------------------------------------------------------------------------------- 1 | // 2 | // Status.m 3 | // TwitterClient 4 | // 5 | // Created by Mike Laurence on 2/9/10. 6 | // Copyright 2010 Mike Laurence. All rights reserved. 7 | // 8 | 9 | #import "Status.h" 10 | 11 | 12 | @implementation Status 13 | 14 | @dynamic createdAt; 15 | @dynamic resourceId; 16 | @dynamic text; 17 | @dynamic user; 18 | 19 | + (NSString*) remoteURLForCollectionAction:(Action)action { 20 | return @"http://twitter.com/statuses/public_timeline"; 21 | } 22 | 23 | + (NSString*) bundlePathForCollectionAction:(Action)action { 24 | return @"users.mikelaurence"; 25 | } 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /Examples/TwitterClient/Classes/StatusesController.h: -------------------------------------------------------------------------------- 1 | // 2 | // StatusesController.h 3 | // TwitterClient 4 | // 5 | // Created by Mike Laurence on 2/9/10. 6 | // Copyright 2010 Mike Laurence. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CoreTableController.h" 11 | 12 | @interface StatusesController : CoreTableController { 13 | } 14 | 15 | @end 16 | -------------------------------------------------------------------------------- /Examples/TwitterClient/Classes/StatusesController.m: -------------------------------------------------------------------------------- 1 | // 2 | // StatusesController.m 3 | // TwitterClient 4 | // 5 | // Created by Mike Laurence on 2/9/10. 6 | // Copyright Mike Laurence 2010. All rights reserved. 7 | // 8 | 9 | #import "StatusesController.h" 10 | #import "Status.h" 11 | #import "DynamicCell.h" 12 | #import "NSDate+Helper.h" 13 | #import "CoreUtils.h" 14 | 15 | 16 | @implementation StatusesController 17 | 18 | - (Class) model { return [Status class]; } 19 | 20 | - (void) viewWillAppear:(BOOL)animated { 21 | [super viewWillAppear:YES]; 22 | 23 | // Send off remote find request 24 | [Status findAllRemote]; 25 | 26 | // Activate local & remote fetch of statuses 27 | [[self coreResultsController] fetch:$D( 28 | @"createdAt DESC", @"$sort", 29 | @"statusList", @"$template")]; 30 | } 31 | 32 | - (UITableViewCell*)tableView:(UITableView*)tableView resultCellForRowAtIndexPath:(NSIndexPath*)indexPath { 33 | 34 | // Get/create dynamic cell 35 | DynamicCell *cell = (DynamicCell*)[tableView dequeueReusableCellWithIdentifier:@"StatusCell"]; 36 | if (cell == nil) { 37 | cell = [DynamicCell cellWithReuseIdentifier:@"StatusCell"]; 38 | cell.defaultFont = [UIFont systemFontOfSize:14.0]; 39 | } 40 | 41 | // Get resource at index path 42 | Status *status = (Status*)[self resourceAtIndexPath:indexPath]; 43 | 44 | // Customize cell 45 | [cell reset]; 46 | [cell addLabelWithText:status.text]; 47 | UILabel *dateLabel = [cell addLabelWithText:[status.createdAt stringDaysAgoAgainstMidnight:YES] andFont:[UIFont italicSystemFontOfSize:12.0]]; 48 | dateLabel.textColor = [UIColor grayColor]; 49 | [cell prepare]; 50 | 51 | return cell; 52 | } 53 | 54 | @end 55 | 56 | -------------------------------------------------------------------------------- /Examples/TwitterClient/Classes/TwitterClientAppDelegate.h: -------------------------------------------------------------------------------- 1 | // 2 | // TwitterClientAppDelegate.h 3 | // TwitterClient 4 | // 5 | // Created by Mike Laurence on 2/9/10. 6 | // Copyright 2010 Mike Laurence. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CoreManager.h" 11 | 12 | @interface TwitterClientAppDelegate : NSObject { 13 | UIWindow *window; 14 | UINavigationController *navigationController; 15 | 16 | CoreManager *coreManager; 17 | } 18 | 19 | @property (nonatomic, retain) IBOutlet UIWindow *window; 20 | @property (nonatomic, retain) IBOutlet UINavigationController *navigationController; 21 | 22 | @end 23 | 24 | -------------------------------------------------------------------------------- /Examples/TwitterClient/Classes/TwitterClientAppDelegate.m: -------------------------------------------------------------------------------- 1 | // 2 | // TwitterClientAppDelegate.m 3 | // TwitterClient 4 | // 5 | // Created by Mike Laurence on 2/9/10. 6 | // Copyright 2010 Mike Laurence. All rights reserved. 7 | // 8 | 9 | #import "TwitterClientAppDelegate.h" 10 | 11 | 12 | @implementation TwitterClientAppDelegate 13 | 14 | @synthesize window; 15 | @synthesize navigationController; 16 | 17 | 18 | #pragma mark - 19 | #pragma mark Application lifecycle 20 | 21 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions { 22 | 23 | // Create & configure Core Manager 24 | coreManager = [[CoreManager alloc] init]; 25 | coreManager.remoteSiteURL = @"twitter.com"; 26 | coreManager.logLevel = 5; 27 | 28 | // Set default date format to Twitter standard: Tue Feb 09 19:38:16 +0000 2010 29 | coreManager.defaultDateParser = [[NSDateFormatter alloc] init]; 30 | [coreManager.defaultDateParser setDateFormat:@"EEE MMM dd HH:mm:ss ZZZZ yyyy"]; 31 | 32 | // Configure window 33 | [window addSubview:[navigationController view]]; 34 | [window makeKeyAndVisible]; 35 | 36 | return YES; 37 | } 38 | 39 | 40 | - (void)applicationWillTerminate:(UIApplication *)application { 41 | // Save data if appropriate 42 | } 43 | 44 | 45 | #pragma mark - 46 | #pragma mark Memory management 47 | 48 | - (void)dealloc { 49 | [coreManager release]; 50 | [navigationController release]; 51 | [window release]; 52 | [super dealloc]; 53 | } 54 | 55 | 56 | @end 57 | 58 | -------------------------------------------------------------------------------- /Examples/TwitterClient/Classes/TwitterModel.h: -------------------------------------------------------------------------------- 1 | // 2 | // TwitterModel.h 3 | // TwitterClient 4 | // 5 | // Created by Mike Laurence on 2/9/10. 6 | // Copyright 2010 Mike Laurence. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "CoreResource.h" 11 | 12 | 13 | @interface TwitterModel : CoreResource { 14 | 15 | } 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /Examples/TwitterClient/Classes/TwitterModel.m: -------------------------------------------------------------------------------- 1 | // 2 | // TwitterModel.m 3 | // TwitterClient 4 | // 5 | // Created by Mike Laurence on 2/9/10. 6 | // Copyright 2010 Mike Laurence. All rights reserved. 7 | // 8 | 9 | #import "TwitterModel.h" 10 | #import "NSString+InflectionSupport.h" 11 | 12 | 13 | @implementation TwitterModel 14 | 15 | + (NSString*) localNameForRemoteField:(NSString*)name { 16 | return [name camelize]; 17 | } 18 | 19 | + (NSString*) remoteNameForLocalField:(NSString*)name { 20 | return [name deCamelizeWith:@"_"]; 21 | } 22 | 23 | @end 24 | -------------------------------------------------------------------------------- /Examples/TwitterClient/Classes/User.h: -------------------------------------------------------------------------------- 1 | // 2 | // User.h 3 | // TwitterClient 4 | // 5 | // Created by Mike Laurence on 2/9/10. 6 | // Copyright 2010 Mike Laurence. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "TwitterModel.h" 11 | 12 | @class Status; 13 | 14 | @interface User : TwitterModel { 15 | } 16 | 17 | @property (nonatomic, retain) NSDate *createdAt; 18 | @property (nonatomic, retain) NSString *desc; 19 | @property (nonatomic, retain) NSNumber *following; 20 | @property (nonatomic, retain) NSNumber *friendsCount; 21 | @property (nonatomic, retain) NSString *location; 22 | @property (nonatomic, retain) NSString *name; 23 | @property (nonatomic, retain) NSString *profileImageUrl; 24 | @property (nonatomic, retain) NSNumber *resourceId; 25 | @property (nonatomic, retain) NSNumber *statusesCount; 26 | @property (nonatomic, retain) NSSet *statuses; 27 | 28 | @end 29 | -------------------------------------------------------------------------------- /Examples/TwitterClient/Classes/User.m: -------------------------------------------------------------------------------- 1 | // 2 | // User.m 3 | // TwitterClient 4 | // 5 | // Created by Mike Laurence on 2/9/10. 6 | // Copyright 2010 Mike Laurence. All rights reserved. 7 | // 8 | 9 | #import "User.h" 10 | 11 | 12 | @implementation User 13 | 14 | @dynamic createdAt; 15 | @dynamic desc; 16 | @dynamic following; 17 | @dynamic friendsCount; 18 | @dynamic location; 19 | @dynamic name; 20 | @dynamic profileImageUrl; 21 | @dynamic resourceId; 22 | @dynamic statusesCount; 23 | @dynamic statuses; 24 | 25 | @end 26 | -------------------------------------------------------------------------------- /Examples/TwitterClient/TwitterClient-Info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | CFBundleDevelopmentRegion 6 | English 7 | CFBundleDisplayName 8 | ${PRODUCT_NAME} 9 | CFBundleExecutable 10 | ${EXECUTABLE_NAME} 11 | CFBundleIconFile 12 | 13 | CFBundleIdentifier 14 | org.coreresource.${PRODUCT_NAME:rfc1034identifier} 15 | CFBundleInfoDictionaryVersion 16 | 6.0 17 | CFBundleName 18 | ${PRODUCT_NAME} 19 | CFBundlePackageType 20 | APPL 21 | CFBundleSignature 22 | ???? 23 | CFBundleVersion 24 | 1.0 25 | LSRequiresIPhoneOS 26 | 27 | NSMainNibFile 28 | MainWindow 29 | 30 | 31 | -------------------------------------------------------------------------------- /Examples/TwitterClient/TwitterClient_Prefix.pch: -------------------------------------------------------------------------------- 1 | // 2 | // Prefix header for all source files of the 'TwitterClient' target in the 'TwitterClient' project 3 | // 4 | #import 5 | 6 | #ifndef __IPHONE_3_0 7 | #warning "This project uses features only available in iPhone SDK 3.0 and later." 8 | #endif 9 | 10 | 11 | #ifdef __OBJC__ 12 | #import 13 | #import 14 | #import 15 | #import "CoreUtils.h" 16 | #endif 17 | -------------------------------------------------------------------------------- /Examples/TwitterClient/main.m: -------------------------------------------------------------------------------- 1 | // 2 | // main.m 3 | // TwitterClient 4 | // 5 | // Created by Mike Laurence on 2/9/10. 6 | // Copyright Punkbot LLC 2010. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | int main(int argc, char *argv[]) { 12 | 13 | NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init]; 14 | int retVal = UIApplicationMain(argc, argv, nil, nil); 15 | [pool release]; 16 | return retVal; 17 | } 18 | -------------------------------------------------------------------------------- /Examples/TwitterClient/twitter.xcdatamodel/elements: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikelaurence/CoreResource/9948473ed3ec33ab0c80d7ffc96cbb9e7cd338ad/Examples/TwitterClient/twitter.xcdatamodel/elements -------------------------------------------------------------------------------- /Examples/TwitterClient/twitter.xcdatamodel/layout: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/mikelaurence/CoreResource/9948473ed3ec33ab0c80d7ffc96cbb9e7cd338ad/Examples/TwitterClient/twitter.xcdatamodel/layout -------------------------------------------------------------------------------- /Libraries/ASIHTTPRequest/ASIAuthenticationDialog.h: -------------------------------------------------------------------------------- 1 | // 2 | // ASIAuthenticationDialog.h 3 | // Part of ASIHTTPRequest -> http://allseeing-i.com/ASIHTTPRequest 4 | // 5 | // Created by Ben Copsey on 21/08/2009. 6 | // Copyright 2009 All-Seeing Interactive. All rights reserved. 7 | // 8 | 9 | #import 10 | @class ASIHTTPRequest; 11 | 12 | typedef enum _ASIAuthenticationType { 13 | ASIStandardAuthenticationType = 0, 14 | ASIProxyAuthenticationType = 1 15 | } ASIAuthenticationType; 16 | 17 | @interface ASIAuthenticationDialog : NSObject { 18 | ASIHTTPRequest *request; 19 | UIActionSheet *loginDialog; 20 | ASIAuthenticationType type; 21 | } 22 | + (void)presentAuthenticationDialogForRequest:(ASIHTTPRequest *)request; 23 | + (void)presentProxyAuthenticationDialogForRequest:(ASIHTTPRequest *)request; 24 | 25 | @property (retain) ASIHTTPRequest *request; 26 | @property (retain) UIActionSheet *loginDialog; 27 | @property (assign) ASIAuthenticationType type; 28 | @end 29 | -------------------------------------------------------------------------------- /Libraries/ASIHTTPRequest/ASIFormDataRequest.h: -------------------------------------------------------------------------------- 1 | // 2 | // ASIFormDataRequest.h 3 | // Part of ASIHTTPRequest -> http://allseeing-i.com/ASIHTTPRequest 4 | // 5 | // Created by Ben Copsey on 07/11/2008. 6 | // Copyright 2008-2009 All-Seeing Interactive. All rights reserved. 7 | // 8 | 9 | #import 10 | #import "ASIHTTPRequest.h" 11 | #import "ASIHTTPRequestConfig.h" 12 | 13 | typedef enum _ASIPostFormat { 14 | ASIMultipartFormDataPostFormat = 0, 15 | ASIURLEncodedPostFormat = 1 16 | 17 | } ASIPostFormat; 18 | 19 | @interface ASIFormDataRequest : ASIHTTPRequest { 20 | 21 | // Parameters that will be POSTed to the url 22 | NSMutableDictionary *postData; 23 | 24 | // Files that will be POSTed to the url 25 | NSMutableDictionary *fileData; 26 | 27 | ASIPostFormat postFormat; 28 | 29 | NSStringEncoding stringEncoding; 30 | 31 | #if DEBUG_FORM_DATA_REQUEST 32 | // Will store a string version of the request body that will be printed to the console when ASIHTTPREQUEST_DEBUG is set in GCC_PREPROCESSOR_DEFINITIONS 33 | NSString *debugBodyString; 34 | #endif 35 | 36 | } 37 | 38 | #pragma mark utilities 39 | - (NSString*)encodeURL:(NSString *)string; 40 | 41 | #pragma mark setup request 42 | 43 | // Add a POST variable to the request 44 | - (void)setPostValue:(id )value forKey:(NSString *)key; 45 | 46 | // Add the contents of a local file to the request 47 | - (void)setFile:(NSString *)filePath forKey:(NSString *)key; 48 | 49 | // Same as above, but you can specify the content-type and file name 50 | - (void)setFile:(id)data withFileName:(NSString *)fileName andContentType:(NSString *)contentType forKey:(NSString *)key; 51 | 52 | // Add the contents of an NSData object to the request 53 | - (void)setData:(NSData *)data forKey:(NSString *)key; 54 | 55 | // Same as above, but you can specify the content-type and file name 56 | - (void)setData:(id)data withFileName:(NSString *)fileName andContentType:(NSString *)contentType forKey:(NSString *)key; 57 | 58 | 59 | @property (assign) ASIPostFormat postFormat; 60 | @property (assign) NSStringEncoding stringEncoding; 61 | @end 62 | -------------------------------------------------------------------------------- /Libraries/ASIHTTPRequest/ASIHTTPRequestConfig.h: -------------------------------------------------------------------------------- 1 | // 2 | // ASIHTTPRequestConfig.h 3 | // Part of ASIHTTPRequest -> http://allseeing-i.com/ASIHTTPRequest 4 | // 5 | // Created by Ben Copsey on 14/12/2009. 6 | // Copyright 2009 All-Seeing Interactive. All rights reserved. 7 | // 8 | 9 | 10 | // ====== 11 | // Debug output configuration options 12 | // ====== 13 | 14 | // When set to 1 ASIHTTPRequests will print information about what a request is doing 15 | #ifndef DEBUG_REQUEST_STATUS 16 | #define DEBUG_REQUEST_STATUS 0 17 | #endif 18 | 19 | // When set to 1, ASIFormDataRequests will print information about the request body to the console 20 | #ifndef DEBUG_FORM_DATA_REQUEST 21 | #define DEBUG_FORM_DATA_REQUEST 0 22 | #endif 23 | 24 | // When set to 1, ASIHTTPRequests will print information about bandwidth throttling to the console 25 | #ifndef DEBUG_THROTTLING 26 | #define DEBUG_THROTTLING 0 27 | #endif 28 | 29 | // When set to 1, ASIHTTPRequests will print information about persistent connections to the console 30 | #ifndef DEBUG_PERSISTENT_CONNECTIONS 31 | #define DEBUG_PERSISTENT_CONNECTIONS 0 32 | #endif 33 | 34 | // ====== 35 | // Reachability API (iPhone only) 36 | // ====== 37 | 38 | /* 39 | ASIHTTPRequest uses Apple's Reachability class (http://developer.apple.com/iphone/library/samplecode/Reachability/) to turn bandwidth throttling on and off automatically when shouldThrottleBandwidthForWWAN is set to YES on iPhone OS 40 | 41 | There are two versions of Apple's Reachability class, both of which are included in the source distribution of ASIHTTPRequest in the External/Reachability folder. 42 | 43 | * Version 2.0 is the latest version. You should use this if you are targeting iPhone OS 3.x and later 44 | To use Version 2.0, set this to 1, and include Reachability.h + Reachability.m from the Reachability 2.0 folder in your project 45 | 46 | * Version 1.5 is the old version, but it is compatible with both iPhone OS 2.2.1 and iPhone OS 3.0 and later. You should use this if your application needs to work on iPhone OS 2.2.1. 47 | To use Version 1.5, set this to 0, and include Reachability.h + Reachability.m from the Reachability 1.5 folder in your project 48 | 49 | This config option is not used for apps targeting Mac OS X 50 | */ 51 | 52 | #ifndef REACHABILITY_20_API 53 | #define REACHABILITY_20_API 1 54 | #endif 55 | 56 | -------------------------------------------------------------------------------- /Libraries/ASIHTTPRequest/ASIInputStream.h: -------------------------------------------------------------------------------- 1 | // 2 | // ASIInputStream.h 3 | // Part of ASIHTTPRequest -> http://allseeing-i.com/ASIHTTPRequest 4 | // 5 | // Created by Ben Copsey on 10/08/2009. 6 | // Copyright 2009 All-Seeing Interactive. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @class ASIHTTPRequest; 12 | 13 | // This is a wrapper for NSInputStream that pretends to be an NSInputStream itself 14 | // Subclassing NSInputStream seems to be tricky, and may involve overriding undocumented methods, so we'll cheat instead. 15 | // It is used by ASIHTTPRequest whenever we have a request body, and handles measuring and throttling the bandwidth used for uploading 16 | 17 | @interface ASIInputStream : NSObject { 18 | NSInputStream *stream; 19 | ASIHTTPRequest *request; 20 | } 21 | + (id)inputStreamWithFileAtPath:(NSString *)path request:(ASIHTTPRequest *)request; 22 | + (id)inputStreamWithData:(NSData *)data request:(ASIHTTPRequest *)request; 23 | 24 | @property (retain, nonatomic) NSInputStream *stream; 25 | @property (assign, nonatomic) ASIHTTPRequest *request; 26 | @end 27 | -------------------------------------------------------------------------------- /Libraries/ASIHTTPRequest/ASIInputStream.m: -------------------------------------------------------------------------------- 1 | // 2 | // ASIInputStream.m 3 | // Part of ASIHTTPRequest -> http://allseeing-i.com/ASIHTTPRequest 4 | // 5 | // Created by Ben Copsey on 10/08/2009. 6 | // Copyright 2009 All-Seeing Interactive. All rights reserved. 7 | // 8 | 9 | #import "ASIInputStream.h" 10 | #import "ASIHTTPRequest.h" 11 | 12 | // Used to ensure only one request can read data at once 13 | static NSLock *readLock = nil; 14 | 15 | @implementation ASIInputStream 16 | 17 | + (void)initialize 18 | { 19 | if (self == [ASIInputStream class]) { 20 | readLock = [[NSLock alloc] init]; 21 | } 22 | } 23 | 24 | + (id)inputStreamWithFileAtPath:(NSString *)path request:(ASIHTTPRequest *)request 25 | { 26 | ASIInputStream *stream = [[[self alloc] init] autorelease]; 27 | [stream setRequest:request]; 28 | [stream setStream:[NSInputStream inputStreamWithFileAtPath:path]]; 29 | return stream; 30 | } 31 | 32 | + (id)inputStreamWithData:(NSData *)data request:(ASIHTTPRequest *)request 33 | { 34 | ASIInputStream *stream = [[[self alloc] init] autorelease]; 35 | [stream setRequest:request]; 36 | [stream setStream:[NSInputStream inputStreamWithData:data]]; 37 | return stream; 38 | } 39 | 40 | - (void)dealloc 41 | { 42 | [stream release]; 43 | [super dealloc]; 44 | } 45 | 46 | // Called when CFNetwork wants to read more of our request body 47 | // When throttling is on, we ask ASIHTTPRequest for the maximum amount of data we can read 48 | - (NSInteger)read:(uint8_t *)buffer maxLength:(NSUInteger)len 49 | { 50 | [readLock lock]; 51 | unsigned long toRead = len; 52 | if ([ASIHTTPRequest isBandwidthThrottled]) { 53 | toRead = [ASIHTTPRequest maxUploadReadLength]; 54 | if (toRead > len) { 55 | toRead = len; 56 | } else if (toRead == 0) { 57 | toRead = 1; 58 | } 59 | [request performThrottling]; 60 | } 61 | [ASIHTTPRequest incrementBandwidthUsedInLastSecond:toRead]; 62 | [readLock unlock]; 63 | return [stream read:buffer maxLength:toRead]; 64 | } 65 | 66 | // If we get asked to perform a method we don't have (which is almost all of them), we'll just forward the message to our stream 67 | 68 | - (NSMethodSignature *)methodSignatureForSelector:(SEL)aSelector 69 | { 70 | return [stream methodSignatureForSelector:aSelector]; 71 | } 72 | 73 | - (void)forwardInvocation:(NSInvocation *)anInvocation 74 | { 75 | [anInvocation invokeWithTarget:stream]; 76 | } 77 | 78 | @synthesize stream; 79 | @synthesize request; 80 | @end 81 | -------------------------------------------------------------------------------- /Libraries/ASIHTTPRequest/ASINSStringAdditions.h: -------------------------------------------------------------------------------- 1 | // 2 | // ASINSStringAdditions.h 3 | // Part of ASIHTTPRequest -> http://allseeing-i.com/ASIHTTPRequest 4 | // 5 | // Created by Ben Copsey on 12/09/2008. 6 | // Copyright 2008 All-Seeing Interactive. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSString (CookieValueEncodingAdditions) 12 | 13 | - (NSString *)encodedCookieValue; 14 | - (NSString *)decodedCookieValue; 15 | 16 | @end 17 | -------------------------------------------------------------------------------- /Libraries/ASIHTTPRequest/ASINSStringAdditions.m: -------------------------------------------------------------------------------- 1 | // 2 | // ASINSStringAdditions.m 3 | // Part of ASIHTTPRequest -> http://allseeing-i.com/ASIHTTPRequest 4 | // 5 | // Created by Ben Copsey on 12/09/2008. 6 | // Copyright 2008 All-Seeing Interactive. All rights reserved. 7 | // 8 | 9 | #import "ASINSStringAdditions.h" 10 | 11 | @implementation NSString (CookieValueEncodingAdditions) 12 | 13 | - (NSString *)decodedCookieValue 14 | { 15 | NSMutableString *s = [NSMutableString stringWithString:[self stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding]]; 16 | //Also swap plus signs for spaces 17 | [s replaceOccurrencesOfString:@"+" withString:@" " options:NSLiteralSearch range:NSMakeRange(0, [s length])]; 18 | return [NSString stringWithString:s]; 19 | } 20 | 21 | - (NSString *)encodedCookieValue 22 | { 23 | return [self stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 24 | } 25 | 26 | @end 27 | 28 | 29 | -------------------------------------------------------------------------------- /Libraries/DynamicCell/DynamicCell.h: -------------------------------------------------------------------------------- 1 | // 2 | // DynamicCell.h 3 | // 4 | // Created by Mike Laurence on 2/5/10. 5 | // Copyright 2010 Pathfinder Development. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | @interface DynamicCell : UITableViewCell { 11 | // Layout attributes 12 | NSArray *columnPositions; 13 | NSArray *rowPositions; 14 | float rowSpacing; 15 | float columnSpacing; 16 | BOOL maximizeWidth; 17 | 18 | // Container attributes 19 | float paddingTop; 20 | float paddingBottom; 21 | float paddingLeft; 22 | float paddingRight; 23 | 24 | // Defaults 25 | NSArray *defaultRowPositions; 26 | NSArray *defaultColumnPositions; 27 | float defaultRowSpacing; 28 | float defaultColumnSpacing; 29 | float defaultPadding; 30 | UIColor *defaultTextColor; 31 | UIFont *defaultFont; 32 | 33 | // Internals 34 | NSMutableSet *unusedSubviews; 35 | NSMutableArray *placedSubviews; 36 | float height; 37 | float rowHeight; 38 | int currentFloat; 39 | BOOL needsPreparation; 40 | 41 | // View access 42 | NSMutableDictionary* primaryViewsByClass; 43 | } 44 | 45 | // Properties 46 | @property (nonatomic, retain) NSArray *rowPositions; 47 | @property (nonatomic, retain) NSArray *columnPositions; 48 | @property (nonatomic, assign) float rowSpacing; 49 | @property (nonatomic, assign) float columnSpacing; 50 | @property (nonatomic, assign) BOOL maximizeWidth; 51 | 52 | @property (nonatomic, assign) float paddingTop; 53 | @property (nonatomic, assign) float paddingBottom; 54 | @property (nonatomic, assign) float paddingLeft; 55 | @property (nonatomic, assign) float paddingRight; 56 | 57 | // Defaults 58 | @property (nonatomic, retain) NSArray *defaultRowPositions; 59 | @property (nonatomic, retain) NSArray *defaultColumnPositions; 60 | @property (nonatomic, assign) float defaultRowSpacing; 61 | @property (nonatomic, assign) float defaultColumnSpacing; 62 | @property (nonatomic, assign) float defaultPadding; 63 | @property (nonatomic, retain) UIColor *defaultTextColor; 64 | @property (nonatomic, retain) UIFont *defaultFont; 65 | 66 | + (id) cellWithReuseIdentifier:(NSString*)reuseIdentifier; 67 | - (id) initWithReuseIdentifier:(NSString*)reuseIdentifier; 68 | 69 | - (void) reset; 70 | - (void) prepare; 71 | - (NSNumber*) height; 72 | - (void) setPadding:(float)padding; 73 | 74 | - (UIView*) viewOfClass:(Class)clazz; 75 | 76 | #pragma mark - 77 | #pragma mark Generic Views 78 | - (UIView*) addView:(UIView*)view onNewLine:(BOOL)newLine; 79 | - (UIView*) addViewOfClass:(Class)clazz; 80 | - (UIView*) addViewOfClass:(Class)clazz onNewLine:(BOOL)newLine; 81 | 82 | #pragma mark - 83 | #pragma mark Labels 84 | - (UILabel*) addLabelWithText:(NSString*)text; 85 | - (UILabel*) addLabelWithText:(NSString*)text onNewLine:(BOOL)newLine; 86 | - (UILabel*) addLabelWithText:(NSString*)text andFont:(UIFont*)font; 87 | - (UILabel*) addLabelWithText:(NSString*)text andFont:(UIFont*)font onNewLine:(BOOL)newLine; 88 | 89 | #pragma mark - 90 | #pragma mark Text Views 91 | - (UITextView*) addTextViewWithText:(NSString*)text; 92 | - (UITextView*) addTextViewText:(NSString*)text onNewLine:(BOOL)newLine; 93 | - (UITextView*) addTextViewText:(NSString*)text andFont:(UIFont*)font; 94 | - (UITextView*) addTextViewText:(NSString*)text andFont:(UIFont*)font onNewLine:(BOOL)newLine; 95 | 96 | #pragma mark - 97 | #pragma mark Images 98 | - (UIImageView*) addImage:(UIImage*)image; 99 | - (UIImageView*) addImage:(UIImage*)image onNewLine:(BOOL)newLine; 100 | 101 | #pragma mark - 102 | #pragma mark Buttons 103 | - (UIButton*) addButtonOfType:(UIButtonType)type withTitle:(NSString*)title onNewLine:(BOOL)newLine; 104 | - (UIButton*) addButtonOfType:(UIButtonType)type withTitle:(NSString*)title andTarget:(id)target action:(SEL)action; 105 | - (UIButton*) addButtonOfType:(UIButtonType)type withTitle:(NSString*)title andTarget:(id)target action:(SEL)action onNewLine:(BOOL)newLine; 106 | - (UIButton*) buttonOfType:(UIButtonType)type; 107 | 108 | #pragma mark - 109 | #pragma mark External view access 110 | - (UIButton*) button; 111 | - (UITextField*) textField; 112 | 113 | @end 114 | -------------------------------------------------------------------------------- /Libraries/JSON/JSON.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2009 Stig Brautaset. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of the author nor the names of its contributors may be used 15 | to endorse or promote products derived from this software without specific 16 | prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | /** 31 | @mainpage A strict JSON parser and generator for Objective-C 32 | 33 | JSON (JavaScript Object Notation) is a lightweight data-interchange 34 | format. This framework provides two apis for parsing and generating 35 | JSON. One standard object-based and a higher level api consisting of 36 | categories added to existing Objective-C classes. 37 | 38 | Learn more on the http://code.google.com/p/json-framework project site. 39 | 40 | This framework does its best to be as strict as possible, both in what it 41 | accepts and what it generates. For example, it does not support trailing commas 42 | in arrays or objects. Nor does it support embedded comments, or 43 | anything else not in the JSON specification. This is considered a feature. 44 | 45 | */ 46 | 47 | #import "SBJSON.h" 48 | #import "NSObject+SBJSON.h" 49 | #import "NSString+SBJSON.h" 50 | 51 | -------------------------------------------------------------------------------- /Libraries/JSON/NSObject+SBJSON.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2009 Stig Brautaset. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of the author nor the names of its contributors may be used 15 | to endorse or promote products derived from this software without specific 16 | prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #import 31 | 32 | 33 | /** 34 | @brief Adds JSON generation to Foundation classes 35 | 36 | This is a category on NSObject that adds methods for returning JSON representations 37 | of standard objects to the objects themselves. This means you can call the 38 | -JSONRepresentation method on an NSArray object and it'll do what you want. 39 | */ 40 | @interface NSObject (NSObject_SBJSON) 41 | 42 | /** 43 | @brief Returns a string containing the receiver encoded as a JSON fragment. 44 | 45 | This method is added as a category on NSObject but is only actually 46 | supported for the following objects: 47 | @li NSDictionary 48 | @li NSArray 49 | @li NSString 50 | @li NSNumber (also used for booleans) 51 | @li NSNull 52 | 53 | @deprecated Given we bill ourselves as a "strict" JSON library, this method should be removed. 54 | */ 55 | - (NSString *)JSONFragment; 56 | 57 | /** 58 | @brief Returns a string containing the receiver encoded in JSON. 59 | 60 | This method is added as a category on NSObject but is only actually 61 | supported for the following objects: 62 | @li NSDictionary 63 | @li NSArray 64 | */ 65 | - (NSString *)JSONRepresentation; 66 | 67 | @end 68 | 69 | -------------------------------------------------------------------------------- /Libraries/JSON/NSObject+SBJSON.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2009 Stig Brautaset. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of the author nor the names of its contributors may be used 15 | to endorse or promote products derived from this software without specific 16 | prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #import "NSObject+SBJSON.h" 31 | #import "SBJsonWriter.h" 32 | 33 | static const SBJsonWriter *jsonWriter; 34 | 35 | @implementation NSObject (NSObject_SBJSON) 36 | 37 | - (NSString *)JSONFragment { 38 | if (!jsonWriter) 39 | jsonWriter = [SBJsonWriter new]; 40 | 41 | NSString *json = [jsonWriter stringWithFragment:self]; 42 | if (json) 43 | return json; 44 | 45 | NSLog(@"-JSONFragment failed. Error trace is: %@", [jsonWriter errorTrace]); 46 | return nil; 47 | } 48 | 49 | - (NSString *)JSONRepresentation { 50 | if (!jsonWriter) 51 | jsonWriter = [SBJsonWriter new]; 52 | 53 | NSString *json = [jsonWriter stringWithObject:self]; 54 | if (json) 55 | return json; 56 | 57 | NSLog(@"-JSONRepresentation failed. Error trace is: %@", [jsonWriter errorTrace]); 58 | return nil; 59 | } 60 | 61 | @end 62 | -------------------------------------------------------------------------------- /Libraries/JSON/NSString+SBJSON.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2009 Stig Brautaset. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of the author nor the names of its contributors may be used 15 | to endorse or promote products derived from this software without specific 16 | prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #import 31 | 32 | /** 33 | @brief Adds JSON parsing methods to NSString 34 | 35 | This is a category on NSString that adds methods for parsing the target string. 36 | */ 37 | @interface NSString (NSString_SBJSON) 38 | 39 | 40 | /** 41 | @brief Returns the object represented in the receiver, or nil on error. 42 | 43 | Returns a a scalar object represented by the string's JSON fragment representation. 44 | 45 | @deprecated Given we bill ourselves as a "strict" JSON library, this method should be removed. 46 | */ 47 | - (id)JSONFragmentValue; 48 | 49 | /** 50 | @brief Returns the NSDictionary or NSArray represented by the current string's JSON representation. 51 | 52 | Returns the dictionary or array represented in the receiver, or nil on error. 53 | 54 | Returns the NSDictionary or NSArray represented by the current string's JSON representation. 55 | */ 56 | - (id)JSONValue; 57 | 58 | @end 59 | -------------------------------------------------------------------------------- /Libraries/JSON/NSString+SBJSON.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2007-2009 Stig Brautaset. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of the author nor the names of its contributors may be used 15 | to endorse or promote products derived from this software without specific 16 | prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #import "NSString+SBJSON.h" 31 | #import "SBJsonParser.h" 32 | 33 | static const SBJsonParser *jsonParser; 34 | 35 | @implementation NSString (NSString_SBJSON) 36 | 37 | - (id)JSONFragmentValue 38 | { 39 | if (!jsonParser) 40 | jsonParser = [SBJsonParser new]; 41 | 42 | id repr = [jsonParser fragmentWithString:self]; 43 | if (repr) 44 | return repr; 45 | 46 | NSLog(@"-JSONFragmentValue failed. Error trace is: %@", [jsonParser errorTrace]); 47 | return nil; 48 | } 49 | 50 | - (id)JSONValue 51 | { 52 | if (!jsonParser) 53 | jsonParser = [SBJsonParser new]; 54 | 55 | id repr = [jsonParser objectWithString:self]; 56 | if (repr) 57 | return repr; 58 | 59 | NSLog(@"-JSONValue failed. Error trace is: %@", [jsonParser errorTrace]); 60 | return nil; 61 | } 62 | 63 | @end 64 | -------------------------------------------------------------------------------- /Libraries/JSON/SBJSON.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2007-2009 Stig Brautaset. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of the author nor the names of its contributors may be used 15 | to endorse or promote products derived from this software without specific 16 | prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #import 31 | #import "SBJsonParser.h" 32 | #import "SBJsonWriter.h" 33 | 34 | /** 35 | @brief Facade for SBJsonWriter/SBJsonParser. 36 | 37 | Requests are forwarded to instances of SBJsonWriter and SBJsonParser. 38 | */ 39 | @interface SBJSON : SBJsonBase { 40 | 41 | @private 42 | SBJsonParser *jsonParser; 43 | SBJsonWriter *jsonWriter; 44 | } 45 | 46 | 47 | /// Return the fragment represented by the given string 48 | - (id)fragmentWithString:(NSString*)jsonrep 49 | error:(NSError**)error; 50 | 51 | /// Return the object represented by the given string 52 | - (id)objectWithString:(NSString*)jsonrep 53 | error:(NSError**)error; 54 | 55 | /// Parse the string and return the represented object (or scalar) 56 | - (id)objectWithString:(id)value 57 | allowScalar:(BOOL)x 58 | error:(NSError**)error; 59 | 60 | 61 | /// Return JSON representation of an array or dictionary 62 | - (NSString*)stringWithObject:(id)value 63 | error:(NSError**)error; 64 | 65 | /// Return JSON representation of any legal JSON value 66 | - (NSString*)stringWithFragment:(id)value 67 | error:(NSError**)error; 68 | 69 | /// Return JSON representation (or fragment) for the given object 70 | - (NSString*)stringWithObject:(id)value 71 | allowScalar:(BOOL)x 72 | error:(NSError**)error; 73 | 74 | 75 | @end 76 | -------------------------------------------------------------------------------- /Libraries/JSON/SBJsonBase.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2009 Stig Brautaset. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of the author nor the names of its contributors may be used 15 | to endorse or promote products derived from this software without specific 16 | prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #import 31 | 32 | extern NSString * SBJSONErrorDomain; 33 | 34 | 35 | enum { 36 | EUNSUPPORTED = 1, 37 | EPARSENUM, 38 | EPARSE, 39 | EFRAGMENT, 40 | ECTRL, 41 | EUNICODE, 42 | EDEPTH, 43 | EESCAPE, 44 | ETRAILCOMMA, 45 | ETRAILGARBAGE, 46 | EEOF, 47 | EINPUT 48 | }; 49 | 50 | /** 51 | @brief Common base class for parsing & writing. 52 | 53 | This class contains the common error-handling code and option between the parser/writer. 54 | */ 55 | @interface SBJsonBase : NSObject { 56 | NSMutableArray *errorTrace; 57 | 58 | @protected 59 | NSUInteger depth, maxDepth; 60 | } 61 | 62 | /** 63 | @brief The maximum recursing depth. 64 | 65 | Defaults to 512. If the input is nested deeper than this the input will be deemed to be 66 | malicious and the parser returns nil, signalling an error. ("Nested too deep".) You can 67 | turn off this security feature by setting the maxDepth value to 0. 68 | */ 69 | @property NSUInteger maxDepth; 70 | 71 | /** 72 | @brief Return an error trace, or nil if there was no errors. 73 | 74 | Note that this method returns the trace of the last method that failed. 75 | You need to check the return value of the call you're making to figure out 76 | if the call actually failed, before you know call this method. 77 | */ 78 | @property(copy,readonly) NSArray* errorTrace; 79 | 80 | /// @internal for use in subclasses to add errors to the stack trace 81 | - (void)addErrorWithCode:(NSUInteger)code description:(NSString*)str; 82 | 83 | /// @internal for use in subclasess to clear the error before a new parsing attempt 84 | - (void)clearErrorTrace; 85 | 86 | @end 87 | -------------------------------------------------------------------------------- /Libraries/JSON/SBJsonBase.m: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2009 Stig Brautaset. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of the author nor the names of its contributors may be used 15 | to endorse or promote products derived from this software without specific 16 | prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #import "SBJsonBase.h" 31 | NSString * SBJSONErrorDomain = @"org.brautaset.JSON.ErrorDomain"; 32 | 33 | 34 | @implementation SBJsonBase 35 | 36 | @synthesize errorTrace; 37 | @synthesize maxDepth; 38 | 39 | - (id)init { 40 | self = [super init]; 41 | if (self) 42 | self.maxDepth = 512; 43 | return self; 44 | } 45 | 46 | - (void)dealloc { 47 | [errorTrace release]; 48 | [super dealloc]; 49 | } 50 | 51 | - (void)addErrorWithCode:(NSUInteger)code description:(NSString*)str { 52 | NSDictionary *userInfo; 53 | if (!errorTrace) { 54 | errorTrace = [NSMutableArray new]; 55 | userInfo = [NSDictionary dictionaryWithObject:str forKey:NSLocalizedDescriptionKey]; 56 | 57 | } else { 58 | userInfo = [NSDictionary dictionaryWithObjectsAndKeys: 59 | str, NSLocalizedDescriptionKey, 60 | [errorTrace lastObject], NSUnderlyingErrorKey, 61 | nil]; 62 | } 63 | 64 | NSError *error = [NSError errorWithDomain:SBJSONErrorDomain code:code userInfo:userInfo]; 65 | 66 | [self willChangeValueForKey:@"errorTrace"]; 67 | [errorTrace addObject:error]; 68 | [self didChangeValueForKey:@"errorTrace"]; 69 | } 70 | 71 | - (void)clearErrorTrace { 72 | [self willChangeValueForKey:@"errorTrace"]; 73 | [errorTrace release]; 74 | errorTrace = nil; 75 | [self didChangeValueForKey:@"errorTrace"]; 76 | } 77 | 78 | @end 79 | -------------------------------------------------------------------------------- /Libraries/JSON/SBJsonParser.h: -------------------------------------------------------------------------------- 1 | /* 2 | Copyright (C) 2009 Stig Brautaset. All rights reserved. 3 | 4 | Redistribution and use in source and binary forms, with or without 5 | modification, are permitted provided that the following conditions are met: 6 | 7 | * Redistributions of source code must retain the above copyright notice, this 8 | list of conditions and the following disclaimer. 9 | 10 | * Redistributions in binary form must reproduce the above copyright notice, 11 | this list of conditions and the following disclaimer in the documentation 12 | and/or other materials provided with the distribution. 13 | 14 | * Neither the name of the author nor the names of its contributors may be used 15 | to endorse or promote products derived from this software without specific 16 | prior written permission. 17 | 18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE 21 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 22 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 23 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 24 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 25 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 26 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 | */ 29 | 30 | #import 31 | #import "SBJsonBase.h" 32 | 33 | /** 34 | @brief Options for the parser class. 35 | 36 | This exists so the SBJSON facade can implement the options in the parser without having to re-declare them. 37 | */ 38 | @protocol SBJsonParser 39 | 40 | /** 41 | @brief Return the object represented by the given string. 42 | 43 | Returns the object represented by the passed-in string or nil on error. The returned object can be 44 | a string, number, boolean, null, array or dictionary. 45 | 46 | @param repr the json string to parse 47 | */ 48 | - (id)objectWithString:(NSString *)repr; 49 | 50 | @end 51 | 52 | 53 | /** 54 | @brief The JSON parser class. 55 | 56 | JSON is mapped to Objective-C types in the following way: 57 | 58 | @li Null -> NSNull 59 | @li String -> NSMutableString 60 | @li Array -> NSMutableArray 61 | @li Object -> NSMutableDictionary 62 | @li Boolean -> NSNumber (initialised with -initWithBool:) 63 | @li Number -> NSDecimalNumber 64 | 65 | Since Objective-C doesn't have a dedicated class for boolean values, these turns into NSNumber 66 | instances. These are initialised with the -initWithBool: method, and 67 | round-trip back to JSON properly. (They won't silently suddenly become 0 or 1; they'll be 68 | represented as 'true' and 'false' again.) 69 | 70 | JSON numbers turn into NSDecimalNumber instances, 71 | as we can thus avoid any loss of precision. (JSON allows ridiculously large numbers.) 72 | 73 | */ 74 | @interface SBJsonParser : SBJsonBase { 75 | 76 | @private 77 | const char *c; 78 | } 79 | 80 | @end 81 | 82 | // don't use - exists for backwards compatibility with 2.1.x only. Will be removed in 2.3. 83 | @interface SBJsonParser (Private) 84 | - (id)fragmentWithString:(id)repr; 85 | @end 86 | 87 | 88 | -------------------------------------------------------------------------------- /Libraries/KissXML/DDXML.h: -------------------------------------------------------------------------------- 1 | #import "DDXMLNode.h" 2 | #import "DDXMLElement.h" 3 | #import "DDXMLDocument.h" 4 | -------------------------------------------------------------------------------- /Libraries/KissXML/DDXMLDocument.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import "DDXMLElement.h" 3 | #import "DDXMLNode.h" 4 | 5 | 6 | enum { 7 | DDXMLDocumentXMLKind = 0, 8 | DDXMLDocumentXHTMLKind, 9 | DDXMLDocumentHTMLKind, 10 | DDXMLDocumentTextKind 11 | }; 12 | typedef NSUInteger DDXMLDocumentContentKind; 13 | 14 | @interface DDXMLDocument : DDXMLNode 15 | { 16 | } 17 | 18 | - (id)initWithXMLString:(NSString *)string options:(NSUInteger)mask error:(NSError **)error; 19 | //- (id)initWithContentsOfURL:(NSURL *)url options:(NSUInteger)mask error:(NSError **)error; 20 | - (id)initWithData:(NSData *)data options:(NSUInteger)mask error:(NSError **)error; 21 | //- (id)initWithRootElement:(DDXMLElement *)element; 22 | 23 | //+ (Class)replacementClassForClass:(Class)cls; 24 | 25 | //- (void)setCharacterEncoding:(NSString *)encoding; //primitive 26 | //- (NSString *)characterEncoding; //primitive 27 | 28 | //- (void)setVersion:(NSString *)version; 29 | //- (NSString *)version; 30 | 31 | //- (void)setStandalone:(BOOL)standalone; 32 | //- (BOOL)isStandalone; 33 | 34 | //- (void)setDocumentContentKind:(DDXMLDocumentContentKind)kind; 35 | //- (DDXMLDocumentContentKind)documentContentKind; 36 | 37 | //- (void)setMIMEType:(NSString *)MIMEType; 38 | //- (NSString *)MIMEType; 39 | 40 | //- (void)setDTD:(DDXMLDTD *)documentTypeDeclaration; 41 | //- (DDXMLDTD *)DTD; 42 | 43 | //- (void)setRootElement:(DDXMLNode *)root; 44 | - (DDXMLElement *)rootElement; 45 | 46 | //- (void)insertChild:(DDXMLNode *)child atIndex:(NSUInteger)index; 47 | 48 | //- (void)insertChildren:(NSArray *)children atIndex:(NSUInteger)index; 49 | 50 | //- (void)removeChildAtIndex:(NSUInteger)index; 51 | 52 | //- (void)setChildren:(NSArray *)children; 53 | 54 | //- (void)addChild:(DDXMLNode *)child; 55 | 56 | //- (void)replaceChildAtIndex:(NSUInteger)index withNode:(DDXMLNode *)node; 57 | 58 | - (NSData *)XMLData; 59 | - (NSData *)XMLDataWithOptions:(NSUInteger)options; 60 | 61 | //- (id)objectByApplyingXSLT:(NSData *)xslt arguments:(NSDictionary *)arguments error:(NSError **)error; 62 | //- (id)objectByApplyingXSLTString:(NSString *)xslt arguments:(NSDictionary *)arguments error:(NSError **)error; 63 | //- (id)objectByApplyingXSLTAtURL:(NSURL *)xsltURL arguments:(NSDictionary *)argument error:(NSError **)error; 64 | 65 | //- (BOOL)validateAndReturnError:(NSError **)error; 66 | 67 | @end 68 | -------------------------------------------------------------------------------- /Libraries/KissXML/DDXMLDocument.m: -------------------------------------------------------------------------------- 1 | #import "DDXMLDocument.h" 2 | #import "NSStringAdditions.h" 3 | #import "DDXMLPrivate.h" 4 | 5 | 6 | @implementation DDXMLDocument 7 | 8 | /** 9 | * Returns a DDXML wrapper object for the given primitive node. 10 | * The given node MUST be non-NULL and of the proper type. 11 | * 12 | * If the wrapper object already exists, it is retained/autoreleased and returned. 13 | * Otherwise a new wrapper object is alloc/init/autoreleased and returned. 14 | **/ 15 | + (id)nodeWithPrimitive:(xmlKindPtr)kindPtr 16 | { 17 | // If a wrapper object already exists, the _private variable is pointing to it. 18 | 19 | xmlDocPtr doc = (xmlDocPtr)kindPtr; 20 | if(doc->_private == NULL) 21 | return [[[DDXMLDocument alloc] initWithCheckedPrimitive:kindPtr] autorelease]; 22 | else 23 | return [[((DDXMLDocument *)(doc->_private)) retain] autorelease]; 24 | } 25 | 26 | /** 27 | * Returns a DDXML wrapper object for the given primitive node. 28 | * The given node MUST be non-NULL and of the proper type. 29 | * 30 | * The given node is checked, meaning a wrapper object for it does not already exist. 31 | **/ 32 | - (id)initWithCheckedPrimitive:(xmlKindPtr)kindPtr 33 | { 34 | self = [super initWithCheckedPrimitive:kindPtr]; 35 | return self; 36 | } 37 | 38 | /** 39 | * Initializes and returns a DDXMLDocument object created from an NSData object. 40 | * 41 | * Returns an initialized DDXMLDocument object, or nil if initialization fails 42 | * because of parsing errors or other reasons. 43 | **/ 44 | - (id)initWithXMLString:(NSString *)string options:(NSUInteger)mask error:(NSError **)error 45 | { 46 | return [self initWithData:[string dataUsingEncoding:NSUTF8StringEncoding] options:mask error:error]; 47 | } 48 | 49 | /** 50 | * Initializes and returns a DDXMLDocument object created from an NSData object. 51 | * 52 | * Returns an initialized DDXMLDocument object, or nil if initialization fails 53 | * because of parsing errors or other reasons. 54 | **/ 55 | - (id)initWithData:(NSData *)data options:(NSUInteger)mask error:(NSError **)error 56 | { 57 | if(data == nil || [data length] == 0) 58 | { 59 | if(error) *error = [NSError errorWithDomain:@"DDXMLErrorDomain" code:0 userInfo:nil]; 60 | 61 | [self release]; 62 | return nil; 63 | } 64 | 65 | // Even though xmlKeepBlanksDefault(0) is called in DDXMLNode's initialize method, 66 | // it has been documented that this call seems to get reset on the iPhone: 67 | // http://code.google.com/p/kissxml/issues/detail?id=8 68 | // 69 | // Therefore, we call it again here just to be safe. 70 | xmlKeepBlanksDefault(0); 71 | 72 | xmlDocPtr doc = xmlParseMemory([data bytes], [data length]); 73 | if(doc == NULL) 74 | { 75 | if(error) *error = [NSError errorWithDomain:@"DDXMLErrorDomain" code:1 userInfo:nil]; 76 | 77 | [self release]; 78 | return nil; 79 | } 80 | 81 | return [self initWithCheckedPrimitive:(xmlKindPtr)doc]; 82 | } 83 | 84 | /** 85 | * Returns the root element of the receiver. 86 | **/ 87 | - (DDXMLElement *)rootElement 88 | { 89 | xmlDocPtr doc = (xmlDocPtr)genericPtr; 90 | 91 | // doc->children is a list containing possibly comments, DTDs, etc... 92 | 93 | xmlNodePtr rootNode = xmlDocGetRootElement(doc); 94 | 95 | if(rootNode != NULL) 96 | return [DDXMLElement nodeWithPrimitive:(xmlKindPtr)rootNode]; 97 | else 98 | return nil; 99 | } 100 | 101 | - (NSData *)XMLData 102 | { 103 | return [[self XMLString] dataUsingEncoding:NSUTF8StringEncoding]; 104 | } 105 | 106 | - (NSData *)XMLDataWithOptions:(NSUInteger)options 107 | { 108 | return [[self XMLStringWithOptions:options] dataUsingEncoding:NSUTF8StringEncoding]; 109 | } 110 | 111 | @end 112 | -------------------------------------------------------------------------------- /Libraries/KissXML/DDXMLElement.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import "DDXMLNode.h" 3 | 4 | 5 | @interface DDXMLElement : DDXMLNode 6 | { 7 | } 8 | 9 | - (id)initWithName:(NSString *)name; 10 | - (id)initWithName:(NSString *)name URI:(NSString *)URI; 11 | - (id)initWithName:(NSString *)name stringValue:(NSString *)string; 12 | - (id)initWithXMLString:(NSString *)string error:(NSError **)error; 13 | 14 | #pragma mark --- Elements by name --- 15 | 16 | - (NSArray *)elementsForName:(NSString *)name; 17 | - (NSArray *)elementsForLocalName:(NSString *)localName URI:(NSString *)URI; 18 | 19 | #pragma mark --- Attributes --- 20 | 21 | - (void)addAttribute:(DDXMLNode *)attribute; 22 | - (void)removeAttributeForName:(NSString *)name; 23 | - (void)setAttributes:(NSArray *)attributes; 24 | //- (void)setAttributesAsDictionary:(NSDictionary *)attributes; 25 | - (NSArray *)attributes; 26 | - (DDXMLNode *)attributeForName:(NSString *)name; 27 | //- (DDXMLNode *)attributeForLocalName:(NSString *)localName URI:(NSString *)URI; 28 | 29 | #pragma mark --- Namespaces --- 30 | 31 | - (void)addNamespace:(DDXMLNode *)aNamespace; 32 | - (void)removeNamespaceForPrefix:(NSString *)name; 33 | - (void)setNamespaces:(NSArray *)namespaces; 34 | - (NSArray *)namespaces; 35 | - (DDXMLNode *)namespaceForPrefix:(NSString *)prefix; 36 | - (DDXMLNode *)resolveNamespaceForName:(NSString *)name; 37 | - (NSString *)resolvePrefixForNamespaceURI:(NSString *)namespaceURI; 38 | 39 | #pragma mark --- Children --- 40 | 41 | - (void)insertChild:(DDXMLNode *)child atIndex:(NSUInteger)index; 42 | //- (void)insertChildren:(NSArray *)children atIndex:(NSUInteger)index; 43 | - (void)removeChildAtIndex:(NSUInteger)index; 44 | - (void)setChildren:(NSArray *)children; 45 | - (void)addChild:(DDXMLNode *)child; 46 | //- (void)replaceChildAtIndex:(NSUInteger)index withNode:(DDXMLNode *)node; 47 | //- (void)normalizeAdjacentTextNodesPreservingCDATA:(BOOL)preserve; 48 | 49 | @end 50 | -------------------------------------------------------------------------------- /Libraries/KissXML/DDXMLElementAdditions.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import "DDXML.h" 3 | 4 | // These methods are not part of the standard NSXML API. 5 | // But any developer working extensively with XML will likely appreciate them. 6 | 7 | @interface DDXMLElement (DDAdditions) 8 | 9 | + (DDXMLElement *)elementWithName:(NSString *)name xmlns:(NSString *)ns; 10 | 11 | - (DDXMLElement *)elementForName:(NSString *)name; 12 | - (DDXMLElement *)elementForName:(NSString *)name xmlns:(NSString *)xmlns; 13 | 14 | - (NSString *)xmlns; 15 | - (void)setXmlns:(NSString *)ns; 16 | 17 | - (void)addAttributeWithName:(NSString *)name stringValue:(NSString *)string; 18 | 19 | - (NSDictionary *)attributesAsDictionary; 20 | 21 | @end 22 | -------------------------------------------------------------------------------- /Libraries/KissXML/DDXMLElementAdditions.m: -------------------------------------------------------------------------------- 1 | #import "DDXMLElementAdditions.h" 2 | 3 | @implementation DDXMLElement (DDAdditions) 4 | 5 | /** 6 | * Quick method to create an element 7 | **/ 8 | + (DDXMLElement *)elementWithName:(NSString *)name xmlns:(NSString *)ns 9 | { 10 | DDXMLElement *element = [DDXMLElement elementWithName:name]; 11 | [element setXmlns:ns]; 12 | return element; 13 | } 14 | 15 | /** 16 | * This method returns the first child element for the given name. 17 | * If no child element exists for the given name, returns nil. 18 | **/ 19 | - (DDXMLElement *)elementForName:(NSString *)name 20 | { 21 | NSArray *elements = [self elementsForName:name]; 22 | if([elements count] > 0) 23 | { 24 | return [elements objectAtIndex:0]; 25 | } 26 | else 27 | { 28 | // Note: If you port this code to work with Apple's NSXML, beware of the following: 29 | // 30 | // There is a bug in the NSXMLElement elementsForName: method. 31 | // Consider the following XML fragment: 32 | // 33 | // 34 | // 35 | // 36 | // 37 | // Calling [query elementsForName:@"x"] results in an empty array! 38 | // 39 | // However, it will work properly if you use the following: 40 | // [query elementsForLocalName:@"x" URI:@"some:other:namespace"] 41 | // 42 | // The trouble with this is that we may not always know the xmlns in advance, 43 | // so in this particular case there is no way to access the element without looping through the children. 44 | // 45 | // This bug was submitted to apple on June 1st, 2007 and was classified as "serious". 46 | // 47 | // --!!-- This bug does NOT exist in DDXML --!!-- 48 | 49 | return nil; 50 | } 51 | } 52 | 53 | /** 54 | * This method returns the first child element for the given name and given xmlns. 55 | * If no child elements exist for the given name and given xmlns, returns nil. 56 | **/ 57 | - (DDXMLElement *)elementForName:(NSString *)name xmlns:(NSString *)xmlns 58 | { 59 | NSArray *elements = [self elementsForLocalName:name URI:xmlns]; 60 | if([elements count] > 0) 61 | { 62 | return [elements objectAtIndex:0]; 63 | } 64 | else 65 | { 66 | return nil; 67 | } 68 | } 69 | 70 | /** 71 | * Returns the common xmlns "attribute", which is only accessible via the namespace methods. 72 | * The xmlns value is often used in jabber elements. 73 | **/ 74 | - (NSString *)xmlns 75 | { 76 | return [[self namespaceForPrefix:@""] stringValue]; 77 | } 78 | 79 | - (void)setXmlns:(NSString *)ns 80 | { 81 | // If you use setURI: then the xmlns won't be displayed in the XMLString. 82 | // Adding the namespace this way works properly. 83 | // 84 | // This applies to both Apple's NSXML and DDXML. 85 | 86 | [self addNamespace:[DDXMLNode namespaceWithName:@"" stringValue:ns]]; 87 | } 88 | 89 | /** 90 | * Shortcut to avoid having to manually create a DDXMLNode everytime. 91 | **/ 92 | - (void)addAttributeWithName:(NSString *)name stringValue:(NSString *)string 93 | { 94 | [self addAttribute:[DDXMLNode attributeWithName:name stringValue:string]]; 95 | } 96 | 97 | /** 98 | * Returns all the attributes as a dictionary. 99 | **/ 100 | - (NSDictionary *)attributesAsDictionary 101 | { 102 | NSArray *attributes = [self attributes]; 103 | NSMutableDictionary *result = [NSMutableDictionary dictionaryWithCapacity:[attributes count]]; 104 | 105 | uint i; 106 | for(i = 0; i < [attributes count]; i++) 107 | { 108 | DDXMLNode *node = [attributes objectAtIndex:i]; 109 | 110 | [result setObject:[node stringValue] forKey:[node name]]; 111 | } 112 | return result; 113 | } 114 | 115 | @end 116 | -------------------------------------------------------------------------------- /Libraries/KissXML/DDXMLPrivate.h: -------------------------------------------------------------------------------- 1 | #import "DDXMLNode.h" 2 | #import "DDXMLElement.h" 3 | #import "DDXMLDocument.h" 4 | 5 | // We can't rely solely on NSAssert, because many developers disable them for release builds. 6 | // Our API contract requires us to keep these assertions intact. 7 | #define DDCheck(condition, desc, ...) { if(!(condition)) { [[NSAssertionHandler currentHandler] handleFailureInMethod:_cmd object:self file:[NSString stringWithUTF8String:__FILE__] lineNumber:__LINE__ description:(desc), ##__VA_ARGS__]; } } 8 | 9 | #define DDLastErrorKey @"DDXML:LastError" 10 | 11 | 12 | @interface DDXMLNode (PrivateAPI) 13 | 14 | + (id)nodeWithUnknownPrimitive:(xmlKindPtr)kindPtr; 15 | 16 | + (id)nodeWithPrimitive:(xmlKindPtr)kindPtr; 17 | - (id)initWithCheckedPrimitive:(xmlKindPtr)kindPtr; 18 | 19 | + (id)nodeWithPrimitive:(xmlNsPtr)ns nsParent:(xmlNodePtr)parent; 20 | - (id)initWithCheckedPrimitive:(xmlNsPtr)ns nsParent:(xmlNodePtr)parent; 21 | 22 | + (BOOL)isXmlAttrPtr:(xmlKindPtr)kindPtr; 23 | - (BOOL)isXmlAttrPtr; 24 | 25 | + (BOOL)isXmlNodePtr:(xmlKindPtr)kindPtr; 26 | - (BOOL)isXmlNodePtr; 27 | 28 | + (BOOL)isXmlDocPtr:(xmlKindPtr)kindPtr; 29 | - (BOOL)isXmlDocPtr; 30 | 31 | + (BOOL)isXmlDtdPtr:(xmlKindPtr)kindPtr; 32 | - (BOOL)isXmlDtdPtr; 33 | 34 | + (BOOL)isXmlNsPtr:(xmlKindPtr)kindPtr; 35 | - (BOOL)isXmlNsPtr; 36 | 37 | - (BOOL)hasParent; 38 | 39 | + (void)recursiveStripDocPointersFromNode:(xmlNodePtr)node; 40 | 41 | + (void)detachAttribute:(xmlAttrPtr)attr fromNode:(xmlNodePtr)node; 42 | + (void)removeAttribute:(xmlAttrPtr)attr fromNode:(xmlNodePtr)node; 43 | + (void)removeAllAttributesFromNode:(xmlNodePtr)node; 44 | 45 | + (void)detachNamespace:(xmlNsPtr)ns fromNode:(xmlNodePtr)node; 46 | + (void)removeNamespace:(xmlNsPtr)ns fromNode:(xmlNodePtr)node; 47 | + (void)removeAllNamespacesFromNode:(xmlNodePtr)node; 48 | 49 | + (void)detachChild:(xmlNodePtr)child fromNode:(xmlNodePtr)node; 50 | + (void)removeChild:(xmlNodePtr)child fromNode:(xmlNodePtr)node; 51 | + (void)removeAllChildrenFromNode:(xmlNodePtr)node; 52 | 53 | + (void)removeAllChildrenFromDoc:(xmlDocPtr)doc; 54 | 55 | - (void)nodeRetain; 56 | - (void)nodeRelease; 57 | 58 | + (NSError *)lastError; 59 | 60 | @end 61 | 62 | @interface DDXMLElement (PrivateAPI) 63 | 64 | + (id)nodeWithPrimitive:(xmlKindPtr)kindPtr; 65 | - (id)initWithCheckedPrimitive:(xmlKindPtr)kindPtr; 66 | 67 | - (NSArray *)elementsWithName:(NSString *)name uri:(NSString *)URI; 68 | 69 | + (DDXMLNode *)resolveNamespaceForPrefix:(NSString *)prefix atNode:(xmlNodePtr)nodePtr; 70 | + (NSString *)resolvePrefixForURI:(NSString *)uri atNode:(xmlNodePtr)nodePtr; 71 | 72 | @end 73 | 74 | @interface DDXMLDocument (PrivateAPI) 75 | 76 | + (id)nodeWithPrimitive:(xmlKindPtr)kindPtr; 77 | - (id)initWithCheckedPrimitive:(xmlKindPtr)kindPtr; 78 | 79 | @end -------------------------------------------------------------------------------- /Libraries/KissXML/NSStringAdditions.h: -------------------------------------------------------------------------------- 1 | #import 2 | #import 3 | 4 | 5 | @interface NSString (NSStringAdditions) 6 | 7 | /** 8 | * xmlChar - A basic replacement for char, a byte in a UTF-8 encoded string. 9 | **/ 10 | - (const xmlChar *)xmlChar; 11 | 12 | - (NSString *)stringByTrimming; 13 | 14 | @end 15 | -------------------------------------------------------------------------------- /Libraries/KissXML/NSStringAdditions.m: -------------------------------------------------------------------------------- 1 | #import "NSStringAdditions.h" 2 | 3 | 4 | @implementation NSString (NSStringAdditions) 5 | 6 | - (const xmlChar *)xmlChar 7 | { 8 | return (const xmlChar *)[self UTF8String]; 9 | } 10 | 11 | #ifdef GNUSTEP 12 | - (NSString *)stringByTrimming 13 | { 14 | return [self stringByTrimmingSpaces]; 15 | } 16 | #else 17 | - (NSString *)stringByTrimming 18 | { 19 | NSMutableString *mStr = [self mutableCopy]; 20 | CFStringTrimWhitespace((CFMutableStringRef)mStr); 21 | 22 | NSString *result = [mStr copy]; 23 | 24 | [mStr release]; 25 | return [result autorelease]; 26 | } 27 | #endif 28 | 29 | @end 30 | -------------------------------------------------------------------------------- /Libraries/NSDate-Helper/NSDate+Helper.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSDate+Helper.h 3 | // Codebook 4 | // 5 | // Created by Billy Gray on 2/26/09. 6 | // Copyright 2009 Zetetic LLC. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSDate (Helper) 12 | 13 | - (NSUInteger)daysAgo; 14 | - (NSUInteger)daysAgoAgainstMidnight; 15 | - (NSString *)stringDaysAgo; 16 | - (NSString *)stringDaysAgoAgainstMidnight:(BOOL)flag; 17 | - (NSUInteger)weekday; 18 | 19 | + (NSString *)dbFormatString; 20 | + (NSDate *)dateFromString:(NSString *)string; 21 | + (NSString *)stringFromDate:(NSDate *)date withFormat:(NSString *)string; 22 | + (NSString *)stringFromDate:(NSDate *)date; 23 | + (NSString *)stringForDisplayFromDate:(NSDate *)date; 24 | + (NSString *)stringForDisplayFromDate:(NSDate *)date prefixed:(BOOL)prefixed; 25 | 26 | - (NSDate *)beginningOfWeek; 27 | - (NSDate *)beginningOfDay; 28 | - (NSDate *)endOfWeek; 29 | 30 | @end -------------------------------------------------------------------------------- /Libraries/NSDate-Helper/README.textile: -------------------------------------------------------------------------------- 1 | h2. NSDate (Helper) 2 | 3 | This is a category for the @NSDate@ class that provides some convenience methods for working with @NSDate@ objects and displaying formatted and relative strings. 4 | 5 | More information can be found at my "initial blog post":http://www.zetetic.net/blog/2009/03/11/nsdate-helper/. 6 | 7 | Anyone is welcome to use it for anything, and to change it as they see fit. If you'd like to contribute back any changes (woot!), please fork and send a pull request! 8 | 9 | h3. Usage 10 | 11 | Full documentation is now up "on the Github wiki for this project":http://wiki.github.com/billymeltdown/nsdate-helper. It's a lot better than this kinda rambling overview here. 12 | 13 | Two convenience methods make it easy for you to display some relative date information. @stringForDisplayFromDate@ gives you the kind of relative format you see in the Notes listing on the iPhone: 14 | 15 |

16 |   NSString *displayString = [NSDate stringForDisplayFromDate:date];
17 | 
18 | 19 | This produces the following kinds of output: 20 | 21 | * '3:42 AM' - if the date is after midnight today 22 | * 'Tuesday' - if the date is within the last seven days 23 | * 'Mar 1' - if the date is within the current calendar year 24 | * 'Mar 1, 2008' - else ;-) 25 | 26 |

27 |   NSString *displayString = [NSDate stringForDisplayFromData:date prefixed:YES];
28 | 
29 | 30 | This produces the same as above, but prefixed with 'at' or 'on' depending on the appropriate English syntax. 31 | 32 | Another set of methods provide days-ago information: 33 | 34 |

35 |   NSDate *date = [NSDate date];
36 |   [date daysAgo]; // provides an NSComponent-based NSUInteger describing days ago.
37 |   [date daysAgoAgainstMidnight]; // better version of daysAgo, works off midnight (hat-tip: "sburlot":http://github.com/sburlot)
38 |   [date stringDaysAgo]; // 'Today', 'Yesterday', or 'N days ago'.
39 | 
40 | 41 | Tired of creating and releasing date formatters? Missing things like @to_s(:db)@? Me, too. @NSDate (Helper)@ has some static methods to make going back and forth between strings and dates a little less painful, and particularly easier when working with database timestamps (a la SQLite): 42 | 43 |

44 |   NSDate *date = [NSDate dateFromString:@"2009-03-01 12:15:23"]; 
45 |   NSString *dbDateString = [NSDate stringFromDate:date]; // returns '2009-03-01 12:15:23'
46 | 
47 | 48 | Who needs NSDateFormatter? 49 | 50 | NSString *otherDateString = [NSDate stringFromDate:date withFormat:@"EEEE"]; // use any format you like 51 | 52 | h3. Installation 53 | 54 | To use it in your Cocoa project, import the header and implementation files, and then add the header to your project's _prefix.pch file so that it's available across your project: 55 | 56 |

57 | #ifdef __OBJC__
58 |     #import 
59 |     #import 
60 |     #import "NSDate+Helper.h"
61 | #endif
62 | 
63 | 64 | 65 | -------------------------------------------------------------------------------- /Libraries/Reachability/Reachability.h: -------------------------------------------------------------------------------- 1 | /* 2 | 3 | File: Reachability.h 4 | Abstract: Basic demonstration of how to use the SystemConfiguration Reachablity APIs. 5 | 6 | Version: 2.0 7 | 8 | Disclaimer: IMPORTANT: This Apple software is supplied to you by Apple Inc. 9 | ("Apple") in consideration of your agreement to the following terms, and your 10 | use, installation, modification or redistribution of this Apple software 11 | constitutes acceptance of these terms. If you do not agree with these terms, 12 | please do not use, install, modify or redistribute this Apple software. 13 | 14 | In consideration of your agreement to abide by the following terms, and subject 15 | to these terms, Apple grants you a personal, non-exclusive license, under 16 | Apple's copyrights in this original Apple software (the "Apple Software"), to 17 | use, reproduce, modify and redistribute the Apple Software, with or without 18 | modifications, in source and/or binary forms; provided that if you redistribute 19 | the Apple Software in its entirety and without modifications, you must retain 20 | this notice and the following text and disclaimers in all such redistributions 21 | of the Apple Software. 22 | Neither the name, trademarks, service marks or logos of Apple Inc. may be used 23 | to endorse or promote products derived from the Apple Software without specific 24 | prior written permission from Apple. Except as expressly stated in this notice, 25 | no other rights or licenses, express or implied, are granted by Apple herein, 26 | including but not limited to any patent rights that may be infringed by your 27 | derivative works or by other works in which the Apple Software may be 28 | incorporated. 29 | 30 | The Apple Software is provided by Apple on an "AS IS" basis. APPLE MAKES NO 31 | WARRANTIES, EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED 32 | WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY AND FITNESS FOR A PARTICULAR 33 | PURPOSE, REGARDING THE APPLE SOFTWARE OR ITS USE AND OPERATION ALONE OR IN 34 | COMBINATION WITH YOUR PRODUCTS. 35 | 36 | IN NO EVENT SHALL APPLE BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR 37 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE 38 | GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 39 | ARISING IN ANY WAY OUT OF THE USE, REPRODUCTION, MODIFICATION AND/OR 40 | DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED AND WHETHER UNDER THEORY OF 41 | CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT LIABILITY OR OTHERWISE, EVEN IF 42 | APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 43 | 44 | Copyright (C) 2009 Apple Inc. All Rights Reserved. 45 | 46 | */ 47 | 48 | 49 | #import 50 | #import 51 | 52 | typedef enum { 53 | NotReachable = 0, 54 | ReachableViaWiFi, 55 | ReachableViaWWAN 56 | } NetworkStatus; 57 | #define kReachabilityChangedNotification @"kNetworkReachabilityChangedNotification" 58 | 59 | @interface Reachability: NSObject 60 | { 61 | BOOL localWiFiRef; 62 | SCNetworkReachabilityRef reachabilityRef; 63 | } 64 | 65 | //reachabilityWithHostName- Use to check the reachability of a particular host name. 66 | + (Reachability*) reachabilityWithHostName: (NSString*) hostName; 67 | 68 | //reachabilityWithAddress- Use to check the reachability of a particular IP address. 69 | + (Reachability*) reachabilityWithAddress: (const struct sockaddr_in*) hostAddress; 70 | 71 | //reachabilityForInternetConnection- checks whether the default route is available. 72 | // Should be used by applications that do not connect to a particular host 73 | + (Reachability*) reachabilityForInternetConnection; 74 | 75 | //reachabilityForLocalWiFi- checks whether a local wifi connection is available. 76 | + (Reachability*) reachabilityForLocalWiFi; 77 | 78 | //Start listening for reachability notifications on the current run loop 79 | - (BOOL) startNotifer; 80 | - (void) stopNotifer; 81 | 82 | - (NetworkStatus) currentReachabilityStatus; 83 | //WWAN may be available, but not active until a connection has been established. 84 | //WiFi may require a connection for VPN on Demand. 85 | - (BOOL) connectionRequired; 86 | @end 87 | 88 | 89 | -------------------------------------------------------------------------------- /NSArray+Core.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSArray+Core.h 3 | // CoreTest 4 | // 5 | // Created by Mike Laurence on 3/11/10. 6 | // Copyright 2010 Mike Laurence. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | @interface NSArray (Core) 12 | 13 | #pragma mark - 14 | #pragma mark Sorting 15 | - (NSArray*) sortedArrayUsingKey:(id)key ascending:(BOOL)ascending; 16 | NSInteger ascendingSort(id obj1, id obj2, void *key); 17 | NSInteger descendingSort(id obj1, id obj2, void *key); 18 | 19 | #pragma mark - 20 | #pragma mark Mapping 21 | - (NSArray*) arrayMappedBySelector:(SEL)selector; 22 | - (NSArray*) arrayMappedBySelector:(SEL)selector withObject:(id)object; 23 | - (NSDictionary*) dictionaryMappedByKey:(id)key; 24 | 25 | 26 | @end 27 | -------------------------------------------------------------------------------- /NSArray+Core.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSArray+Core.m 3 | // CoreTest 4 | // 5 | // Created by Mike Laurence on 3/11/10. 6 | // Copyright 2010 Mike Laurence. All rights reserved. 7 | // 8 | 9 | #import "NSArray+Core.h" 10 | 11 | 12 | @implementation NSArray (Core) 13 | 14 | #pragma mark - 15 | #pragma mark Sorting 16 | 17 | - (NSArray*) sortedArrayUsingKey:(id)key ascending:(BOOL)ascending { 18 | return [self sortedArrayUsingFunction:ascending ? ascendingSort : descendingSort context:key]; 19 | } 20 | 21 | NSInteger ascendingSort(id obj1, id obj2, void *key) { 22 | return [[obj1 objectForKey:key] compare:[obj2 objectForKey:key]]; 23 | } 24 | 25 | NSInteger descendingSort(id obj1, id obj2, void *key) { 26 | return [[obj2 objectForKey:key] compare:[obj1 objectForKey:key]]; 27 | } 28 | 29 | 30 | #pragma mark - 31 | #pragma mark Mapping 32 | 33 | - (NSArray*) arrayMappedBySelector:(SEL)selector { 34 | return [self arrayMappedBySelector:selector withObject:nil]; 35 | } 36 | 37 | - (NSArray*) arrayMappedBySelector:(SEL)selector withObject:(id)object { 38 | NSMutableArray *array = [NSMutableArray arrayWithCapacity:[self count]]; 39 | for (id obj in self) { 40 | if ([obj respondsToSelector:selector]) 41 | [array addObject:[obj performSelector:selector withObject:object]]; 42 | } 43 | return array; 44 | } 45 | 46 | - (NSDictionary*) dictionaryMappedByKey:(id)key { 47 | NSMutableDictionary* dict = [NSMutableDictionary dictionaryWithCapacity:[self count]]; 48 | for (id obj in self) 49 | [dict setObject:obj forKey:[obj valueForKey:key]]; 50 | return dict; 51 | } 52 | 53 | 54 | 55 | @end 56 | -------------------------------------------------------------------------------- /NSMutableArray+Core.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSMutableArray+core.h 3 | // 4 | // Created by Mike Laurence on 1/11/10. 5 | // Copyright 2010 Mike Laurence. All rights reserved. 6 | // 7 | 8 | #import 9 | 10 | 11 | @interface NSMutableArray (Core) 12 | 13 | #pragma mark - 14 | #pragma mark Sorting 15 | 16 | - (void) sortUsingKey:(id)key ascending:(BOOL)ascending; 17 | 18 | 19 | #pragma mark - 20 | #pragma mark Padding 21 | 22 | - (void) padToSize:(int)size; 23 | - (void) padToSize:(int)size withInstancesOfClass:(Class)klass; 24 | - (void) padToSize:(int)size withObject:(id)obj; 25 | - (void) padOrTruncateToSize:(int)size withInstancesOfClass:(Class)klass; 26 | 27 | @end 28 | -------------------------------------------------------------------------------- /NSMutableArray+Core.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSMutableArray+core.m 3 | // 4 | // Created by Mike Laurence on 1/11/10. 5 | // Copyright 2010 Mike Laurence. All rights reserved. 6 | // 7 | 8 | #import "NSMutableArray+Core.h" 9 | #import "NSArray+Core.h" 10 | 11 | 12 | @implementation NSMutableArray (Core) 13 | 14 | #pragma mark - 15 | #pragma mark Sorting 16 | 17 | - (void) sortUsingKey:(id)key ascending:(BOOL)ascending { 18 | [self sortUsingFunction:ascending ? ascendingSort : descendingSort context:key]; 19 | } 20 | 21 | 22 | 23 | #pragma mark - 24 | #pragma mark Padding 25 | 26 | - (void) padToSize:(int)size { 27 | [self padToSize:size withObject:[NSNull null]]; 28 | } 29 | 30 | - (void) padToSize:(int)size withInstancesOfClass:(Class)klass { 31 | for (int i = [self count]; i < size; i++) { 32 | id obj = [[klass alloc] init]; 33 | if ([obj respondsToSelector:@selector(setIndex:)]) { 34 | [obj performSelector:@selector(setIndex:) withObject:[NSNumber numberWithInt:i]]; 35 | } 36 | [self addObject:obj]; 37 | } 38 | } 39 | 40 | - (void) padToSize:(int)size withObject:(id)obj { 41 | for (int i = [self count]; i < size; i++) 42 | [self addObject:obj]; 43 | } 44 | 45 | - (void) padOrTruncateToSize:(int)size withInstancesOfClass:(Class)klass { 46 | if (size > [self count]) 47 | [self padToSize:size withInstancesOfClass:klass]; 48 | else if (size < [self count]) 49 | [self removeObjectsInRange:NSMakeRange(size, [self count] - size)]; 50 | } 51 | 52 | @end 53 | -------------------------------------------------------------------------------- /NSObject+Core.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSObject+Core.h 3 | // Core Resource 4 | // 5 | // Created by Mike Laurence on 2/8/10. 6 | // 7 | 8 | #import 9 | 10 | 11 | @interface NSObject (Core) 12 | 13 | - (id) get:(SEL)selector; 14 | - (id) get:(SEL)selector orDefault:(id)defaultValue; 15 | - (BOOL) isCollection; 16 | 17 | @end 18 | -------------------------------------------------------------------------------- /NSObject+Core.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSObject+Core.m 3 | // Core Resource 4 | // 5 | // Created by Mike Laurence on 2/8/10. 6 | // 7 | 8 | #import "NSObject+Core.h" 9 | 10 | 11 | @implementation NSObject (Core) 12 | 13 | - (id) get:(SEL)selector { 14 | return [self respondsToSelector:selector] ? [self performSelector:selector] : nil; 15 | } 16 | 17 | - (id) get:(SEL)selector orDefault:(id)defaultValue { 18 | if ([self respondsToSelector:selector]) { 19 | id val = [self performSelector:selector]; 20 | if (val != nil) 21 | return val; 22 | } 23 | return defaultValue; 24 | } 25 | 26 | - (BOOL) isCollection { 27 | return [self isKindOfClass:[NSDictionary class]] || 28 | [self isKindOfClass:[NSArray class]] || 29 | [self isKindOfClass:[NSSet class]]; 30 | } 31 | 32 | @end 33 | -------------------------------------------------------------------------------- /NSSet+Core.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSSet+Core.h 3 | // Core Resource 4 | // 5 | // Created by Mike Laurence on 2/5/10. 6 | // Copyright 2010 Mike Laurence. All rights reserved. 7 | // 8 | 9 | #import 10 | 11 | 12 | @interface NSSet (Core) 13 | 14 | - (NSSet*) intersection:(NSSet*)otherSet; 15 | - (NSSet*) difference:(NSSet*)otherSet; 16 | 17 | - (id) objectOfClass:(Class)clazz; 18 | 19 | @end 20 | -------------------------------------------------------------------------------- /NSSet+Core.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSSet+Core.m 3 | // Core Resource 4 | // 5 | // Created by Mike Laurence on 2/5/10. 6 | // Copyright 2010 Mike Laurence. All rights reserved. 7 | // 8 | 9 | #import "NSSet+Core.h" 10 | 11 | 12 | @implementation NSSet (Core) 13 | 14 | - (NSSet*) intersection:(NSSet*)otherSet { 15 | NSMutableSet *intersection = [self mutableCopy]; 16 | [intersection intersectSet:otherSet]; 17 | return intersection; 18 | } 19 | 20 | - (NSSet*) difference:(NSSet*)otherSet { 21 | NSMutableSet *difference = [self mutableCopy]; 22 | [difference minusSet:otherSet]; 23 | return difference; 24 | } 25 | 26 | - (id) objectOfClass:(Class)clazz { 27 | for (id obj in self) { 28 | if ([obj isKindOfClass:clazz]) 29 | return obj; 30 | } 31 | return nil; 32 | } 33 | 34 | @end 35 | -------------------------------------------------------------------------------- /NSString+InflectionSupport.h: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+InflectionSupport.h 3 | // 4 | // 5 | // Created by Ryan Daigle on 7/31/08. 6 | // Copyright 2008 yFactorial, LLC. All rights reserved. 7 | // 8 | 9 | @interface NSString (InflectionSupport) 10 | 11 | - (NSString *)deCamelizeWith:(NSString *)delimiter; 12 | 13 | /** 14 | * Return the dashed form af this camelCase string: 15 | * 16 | * [@"camelCase" dasherize] //> @"camel-case" 17 | */ 18 | - (NSString *)dasherize; 19 | 20 | /** 21 | * Return the underscored form af this camelCase string: 22 | * 23 | * [@"camelCase" underscore] //> @"camel_case" 24 | */ 25 | - (NSString *)underscore; 26 | 27 | /** 28 | * Return the camelCase form af this dashed/underscored string: 29 | * 30 | * [@"camel-case_string" camelize] //> @"camelCaseString" 31 | */ 32 | - (NSString*)camelize; 33 | - (NSString*)camelizeCached; 34 | 35 | /** 36 | * Return a copy of the string suitable for displaying in a title. Each word is downcased, with the first letter upcased. 37 | */ 38 | - (NSString *)titleize; 39 | 40 | - (NSString *)decapitalize; 41 | 42 | /** 43 | * Return a copy of the string with the first letter capitalized. 44 | */ 45 | - (NSString *)toClassName; 46 | 47 | - (NSString *)singularize; 48 | 49 | - (NSString *)pluralize; 50 | 51 | @end 52 | -------------------------------------------------------------------------------- /NSString+InflectionSupport.m: -------------------------------------------------------------------------------- 1 | // 2 | // NSString+InflectionSupport.m 3 | // 4 | // 5 | // Created by Ryan Daigle on 7/31/08. 6 | // Copyright 2008 yFactorial, LLC. All rights reserved. 7 | // 8 | 9 | #import "NSString+InflectionSupport.h" 10 | 11 | @implementation NSString (InflectionSupport) 12 | 13 | static NSMutableDictionary *cachedCamelized; 14 | 15 | - (NSCharacterSet *)capitals { 16 | return [NSCharacterSet uppercaseLetterCharacterSet]; 17 | } 18 | 19 | - (NSString *)deCamelizeWith:(NSString *)delimiter { 20 | 21 | unichar *buffer = calloc([self length], sizeof(unichar)); 22 | [self getCharacters:buffer ]; 23 | NSMutableString *underscored = [NSMutableString string]; 24 | 25 | NSString *currChar; 26 | for (int i = 0; i < [self length]; i++) { 27 | currChar = [NSString stringWithCharacters:buffer+i length:1]; 28 | if([[self capitals] characterIsMember:buffer[i]]) { 29 | [underscored appendFormat:@"%@%@", delimiter, [currChar lowercaseString]]; 30 | } else { 31 | [underscored appendString:currChar]; 32 | } 33 | } 34 | 35 | free(buffer); 36 | return underscored; 37 | } 38 | 39 | 40 | - (NSString *)dasherize { 41 | return [self deCamelizeWith:@"-"]; 42 | } 43 | 44 | - (NSString *)underscore { 45 | return [self deCamelizeWith:@"_"]; 46 | } 47 | 48 | - (NSCharacterSet *)camelcaseDelimiters { 49 | return [NSCharacterSet characterSetWithCharactersInString:@"-_"]; 50 | } 51 | 52 | - (NSString *)camelize { 53 | 54 | unichar *buffer = calloc([self length], sizeof(unichar)); 55 | [self getCharacters:buffer ]; 56 | NSMutableString *underscored = [NSMutableString string]; 57 | 58 | BOOL capitalizeNext = NO; 59 | NSCharacterSet *delimiters = [self camelcaseDelimiters]; 60 | for (int i = 0; i < [self length]; i++) { 61 | NSString *currChar = [NSString stringWithCharacters:buffer+i length:1]; 62 | if([delimiters characterIsMember:buffer[i]]) { 63 | capitalizeNext = YES; 64 | } else { 65 | if(capitalizeNext) { 66 | [underscored appendString:[currChar uppercaseString]]; 67 | capitalizeNext = NO; 68 | } else { 69 | [underscored appendString:currChar]; 70 | } 71 | } 72 | } 73 | 74 | free(buffer); 75 | return underscored; 76 | } 77 | 78 | - (NSString*)camelizeCached { 79 | if (cachedCamelized == nil) 80 | cachedCamelized = [[NSMutableDictionary dictionary] retain]; 81 | else { 82 | NSString* cached = [cachedCamelized objectForKey:self]; 83 | if (cached != nil) 84 | return cached; 85 | } 86 | 87 | NSString* camelized = [self camelize]; 88 | [cachedCamelized setObject:camelized forKey:self]; 89 | return camelized; 90 | } 91 | 92 | - (NSString *)titleize { 93 | NSArray *words = [self componentsSeparatedByString:@" "]; 94 | NSMutableString *output = [NSMutableString string]; 95 | for (NSString *word in words) { 96 | [output appendString:[[word substringToIndex:1] uppercaseString]]; 97 | [output appendString:[[word substringFromIndex:1] lowercaseString]]; 98 | [output appendString:@" "]; 99 | } 100 | return [output substringToIndex:[self length]]; 101 | } 102 | 103 | - (NSString *)decapitalize { 104 | return [[[self substringToIndex:1] lowercaseString] stringByAppendingString:[self substringFromIndex:1]]; 105 | } 106 | 107 | - (NSString *)toClassName { 108 | NSString *result = [self camelize]; 109 | return [result stringByReplacingCharactersInRange:NSMakeRange(0,1) 110 | withString:[[result substringWithRange:NSMakeRange(0,1)] uppercaseString]]; 111 | } 112 | 113 | - (NSString *)singularize { 114 | return [self hasSuffix:@"s"] ? [self substringToIndex:[self length] - 1] : self; 115 | } 116 | 117 | - (NSString *)pluralize { 118 | return [self hasSuffix:@"s"] ? self : [self stringByAppendingString:@"s"]; 119 | } 120 | 121 | @end 122 | -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | ## Raison d'être 2 | Core Resource strives to provide local & remote resource management for Objective-C in as little code as possible. 3 | 4 | ## Resources 5 | ### Portal 6 | - [Core Resource website](http://coreresource.org) 7 | 8 | ### Documentation 9 | - [Quick Start](http://coreresource.org/quick_start) 10 | - [Tutorials](http://coreresource.org/tutorials) 11 | - [Documentation](http://coreresource.org/documentation) 12 | 13 | ### Community 14 | - [Get Satisfaction: discussions & feature requests](http://getsatisfaction.com/coreresource) 15 | - [Lighthouse: issue tracking](http://coreresource.lighthouseapp.com) 16 | 17 | ### License 18 | 19 | (The MIT License) 20 | 21 | Copyright (c) 2009-2010 Mike Laurence 22 | 23 | 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: 24 | 25 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 26 | 27 | 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. --------------------------------------------------------------------------------