Skip to content

Instantly share code, notes, and snippets.

View blakewatters's full-sized avatar

Blake Watters blakewatters

View GitHub Profile
@blakewatters
blakewatters / gist:5621704
Created May 21, 2013 17:41
Discussion regarding CocoaPods + RestKit + Unit Testing Bundle Target
Sal_: because I am so beyond stumped on this one
[10:53am] Sal_: So for the past 2 years we have had RestKit "vendored" into our project
[10:54am] Sal_: last week we added it as a pod via the .10.3 podspec
[10:54am] Sal_: and all the sudden running the Unit Test target results in an assertion failure in NSManagedObject+ActiveRecord.m
[10:55am] blakewatters: what's the assertion
[10:55am] Sal_: so the assertion is
[10:55am] Sal_: '[RKManagedObjectStore defaultObjectStore] cannot be nil'
[10:55am] Sal_: but here is where it get's weird...
[10:56am] Sal_: i can confirm with vigorous breakpoints and logs that right up until i run a fetch request, the defaultObjecStore is definitely NOT nil
[10:56am] blakewatters: you may have wound up with 2 copies of RK being linked in
@blakewatters
blakewatters / gist:5601038
Created May 17, 2013 18:34
GateGuru Seed Database Import for GateGuru
2013-05-17 14:30:09.619 Generate Seed Database[25343:c07] I restkit.core_data:RKManagedObjectImporter.m:163 Persistent store reset requested before importing. Deleting existing managed object instances...
2013-05-17 14:30:09.667 Generate Seed Database[25343:c07] I restkit.core_data:RKInMemoryManagedObjectCache.m:94 Caching instances of Entity 'Airline' by attributes 'airlineID'
2013-05-17 14:30:10.042 Generate Seed Database[25343:c07] I restkit.core_data:RKManagedObjectImporter.m:226 Imported 1639 objects from file at path '/Users/blake/Library/Application Support/iPhone Simulator/6.1/Applications/33E428B1-0B8D-4E64-BD3C-2BD7A3D50F69/Generate Seed Database.app/SeedJsonFiles/airlines.json'
2013-05-17 14:30:10.152 Generate Seed Database[25343:c07] I restkit.core_data:RKInMemoryManagedObjectCache.m:94 Caching instances of Entity 'Airport' by attributes 'airportID'
2013-05-17 14:30:12.322 Generate Seed Database[25343:c07] I restkit.core_data:RKManagedObjectImporter.m:226 Imported 4039 objects from file at path '/
RKManagedObjectStore *managedObjectStore = [RKObjectManager sharedManager].managedObjectStore;
managedObjectStore = [[RKInMemoryManagedObjectCache alloc] initWithManagedObjectContext:managedObjectStore.persistentStoreManagedObjectContext];
// JSON loaded from '/posts/:postID/tags' looks like:
// [{ "name": "development" }, { "name": "restkit" }]
RKManagedObjectStore *managedObjectStore = [RKManagedObjectStore defaultStore];
RKEntityMapping *tagMapping = [RKEntityMapping mappingForEntityForName:@"Tag" inManagedObjectStore:managedObjectStore];
[tagMapping addAttributeMappingsFromDictionary:@{ @"@metadata.routing.parameters.postID": @"postID", @"name": @"name" }];
[tagMapping addConnectionForRelationship:@"posts" connectedBy:@{ @"postID": @"postID" }];
RKObjectManager *objectManager = [RKObjectManager sharedManager];
RKResponseDescriptor *responseDescriptor = [RKResponseDescriptor responseDescriptorWithMapping:tagMapping pathPattern:@"/posts/:postID/tags" keyPath:nil statusCodes:[NSIndexSet indexSetWithIndex:200]];
{
"amenity": {
"id": 6295,
"name": "WiFi",
"airport_id": 75,
"terminal_id": 5420,
"ad_count": 0,
"photo_count": 0,
"rating_count": 5,
"is_food": false,
@blakewatters
blakewatters / Example Scheme.xml
Created October 27, 2012 18:13
rake schemes:install example task
<?xml version="1.0" encoding="UTF-8"?>
<Scheme
LastUpgradeVersion = "0450"
version = "1.3">
<BuildAction
parallelizeBuildables = "YES"
buildImplicitDependencies = "YES">
<BuildActionEntries>
<BuildActionEntry
buildForTesting = "NO"
@blakewatters
blakewatters / gist:3927174
Created October 21, 2012 14:48
Form Validation Example
@interface LoginForm : NSObject
@property (nonatomic, copy) NSString *username;
@property (nonatomic, copy) NSString *password;
@property (nonatomic, readonly) BOOL isValid;
@end
@implementation LoginForm
// Tell key-value observation that any time one of the keyPaths in the returned set changes, it affects the value
Pod::Spec.new do |s|
s.name = 'RestKit'
s.version = '0.20.0'
s.summary = 'RestKit is a framework for consuming and modeling RESTful web resources on iOS and OS X.'
s.homepage = 'http://www.restkit.org'
s.author = { 'Blake Watters' => 'blakewatters@gmail.com' }
s.source = { :git => 'https://github.com/RestKit/RestKit.git', :branch => 'feature/reboot-networking-layer' }
s.license = 'Apache License, Version 2.0'
# Platform setup
// Add to serializer
if ([mapping isKindOfClass:[RKEntityMapping class]]) {
NSAttributeDescription *attribute = [(RKEntityMapping *)mapping attributesByName:self.sourceKeyPath];
if ([attribute attributeType] == NSBooleanAttributeType) {
transformedValue = [value boolValue] ? @"true" : @"false";
}
}
@blakewatters
blakewatters / gist:1994289
Created March 7, 2012 16:44
iOS 5 Interface Builder, View Controller and ARC Best Practices

Now that the GateGuru team has been developing on the iOS 5 SDK for awhile, I thought I'd pull together some lessons learned.

  • Declare your IBOutlet and IBActions within the private category within your implementation file. This makes them visible to interface builder without cluttering up the external interfaces and leaking implementation details.
  • Declare your IBOutlet properties as (nonatomic, weak). The weak reference implies a non-owning reference and ARC will nil it as necessary.
  • Delegate properties should be (nonatomic, weak) as well.
  • The designated initializer for UIView's is initWithFrame: when initialized programmatically. When loaded from a Storyboard or custom Nib, it is initWithCoder:
  • The designated initializer for UIViewController's is initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil when initialized programmatically. It is initWithCoder: when loaded from a Storyboard or Nib.