Created
August 17, 2012 09:22
-
-
Save hamin/3377350 to your computer and use it in GitHub Desktop.
Create custom classes by custom classes inheriting from NSFNanoObject
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "NSFNanoObject.h" | |
@interface Person : NSFNanoObject | |
@property (nonatomic, strong) NSString *name; | |
@property (nonatomic, strong) NSString *location; | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "Person.h" | |
#import "NanoStore.h" | |
@implementation Person | |
@synthesize name; | |
@synthesize location; | |
- (id)initFromDictionaryRepresentation:(NSDictionary *)theDictionary | |
{ | |
[self clearNulls:theDictionary]; | |
self = [super initFromDictionaryRepresentation:theDictionary]; | |
if (self) { | |
self.name = [theDictionary objectForKey:@"name"]; | |
self.location = [theDictionary objectForKey:@"location"]; | |
} | |
return self; | |
} | |
@end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#import "Person.h" | |
@interface SomeController () | |
@end | |
@implementation SomeController | |
-(void)awakeFromNib | |
{ | |
// ... | |
NSString *thePath = @"~/Desktop/peopleApp.database"; | |
NSFNanoStore *nanoStore = [NSFNanoStore createAndOpenStoreWithType:NSFPersistentStoreType path:thePath error:nil]; | |
// Obtain the engine | |
NSFNanoEngine *nanoStoreEngine = [nanoStore nanoStoreEngine]; | |
// Set the synchronous mode setting | |
[nanoStoreEngine setSynchronousMode:SynchronousModeOff]; | |
[nanoStoreEngine setEncodingType:NSFEncodingUTF16]; | |
// Open the document store | |
[nanoStore openWithError:nil]; | |
// This should initialize a newly created NanoObject for Person as the NanoObject.h suggest | |
// + (NSFNanoObject*)nanoObjectWithDictionary:(NSDictionary *)theDictionary; | |
// /** * Initializes a newly allocated NanoObject with the given dictionary. | |
Person *aPerson = [[Person alloc] initFromDictionaryRepresentation:personDict]; | |
// ... | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@tciuro GREAT! I will be checking for the fix and upgrade NanoStore in my project soon. So far its been a pleasure to work with :). And thanks for the tip for no using properties directly. Still fairly new to Cocoa and Obj-C but so far really enjoying it. Thanks again :)