So in the last two posts I dealt with setting up CoreData within an existing project, binding the data (NSManagedObjects to a control) and actually getting the objects to save to a file (store). In this last entry, I'll deal with pulling data from the file in order to display it in the control. This code assumes you have an NSManagedContext I'm calling newContext.
NSError **theError = nil; // set up an error code// We need to use an NSEntityDescription that the docs describe as being an abstract form of NSManagedObject. (It's like "id" is to classes.)// When we create an NSEntityDescription we need to map it (think cast it) to the entity in our data model we want to read within our context.NSEntityDescription *entityDescription = [NSEntityDescription entityForName:@"Recent" inManagedObjectContext:newContext];NSFetchRequest *request = [[[NSFetchRequest alloc] init] autorelease]; // Create a CoreData fetch request (NSFetchRequest)[request setEntity:entityDescription]; // tell the fetch request what type of entity we want to fetch (using our NSEntityDescription)
// Here we need to specify our NSPredicate (think SQL SELECT predicate) to specify the subset of objects to read from our store.// The bad news is that CoreData predicates don't use SQL syntax, which is a shame. They use their own special syntax which makes learning a bit more problematic// and difficult.// I am keeping things simple here and am going to assume if I don't specify a predicate CoreData will do the sensible thing and return all objects.// (I am just guessing here, since I didn't feel like wading thru the NSPredicate Programming Manual.)// NSPredicate *predicate = [NSPredicate predicateWithFormat:...];// [request setPredicate:predicate];
// Next, we create an NSSortDescriptor which is used to sort the object during the fetch (think an SQL ORDER BY clause.)
// Specify the property name within the entity we want to sort by (I'm using gitName) and the sort order.NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"gitName" ascending:YES];[request setSortDescriptors:[NSArray arrayWithObject:sortDescriptor]]; // tell the NSFetchRequest to use the sort descriptor[sortDescriptor release]; // clean up
NSArray *array = [newContext executeFetchRequest:request error:theError]; // create an array with the results of executing the fetch request on our context.if (array != nil){// move the results to our array of objects which are bound to our control.}else{// Deal with error...}[array release];
//- (NSPersistentStore *)addPersistentStoreWithType:(NSString *)storeType configuration:nil URL:(NSURL *)storeURL options:(NSDictionary *)options error:(NSError **)error // this is what you use to set up the database type, etc. In this snippet I don't worry about it because I just want it to compile and display something.
NSError *error;
// Build an NSURL to our physical database file.NSFileManager *fileManager = [NSFileManager defaultManager];NSString *folder = @"~/Library/Application Support/Tiny±Git/";folder = [folder stringByExpandingTildeInPath];if ([fileManager fileExistsAtPath: folder] == NO){[fileManager createDirectoryAtPath:folder withIntermediateDirectories:NO attributes:nil error:error];}
NSURL *fileURL = [NSURL fileURLWithPath: [folder stringByAppendingPathComponent: @"TinyGit.sqlite"]];// Now tell our NSPersistanceStoreCoordinator the type of DB you want (I'm using SQLite, you can also use XML, etc.)// Pass in our fileURL NSURL which is where the database will be strored.// There are also configurations, and options, but we can ignore this--I'll worry about those once I get this working.[psc addPersistentStoreWithType:NSSQLiteStoreType configuration:nil URL:fileURL options:nil error:error];
[newContext save:error];

Cadbury and Ghana celebrate Fairtrade pact
If you think the drumming gorilla or dancing-eyebrows kids got big heads from starring in Cadbury ads, check out the oversized star of "Zingolo," this new Cadbury video, shot in Ghana. The song is the first single off an album from the firm's Glass and a Half Full Productions celebrating African music and culture, while touting the U.K. confectioner's switch to Fairtrade cocoa. (Cadbury will pay a guaranteed minimum price for Ghanaian cocoa under a £45 million initiative over 10 years.) The song is infectious, and we'll assume Cadbury doesn't really use exploding, psychedelic cocoa beans in its chocolate bars (though it would explain why I feel high after a few bites). Best of all, there's no Phil Collins on the soundtrack.
—Posted by David Gianatasio
Here is the language specification for blocks (that is lambda abstractions) for C, Objective-C & C++ as implemented in the Clang compiler and used in Mac OS X 10.6 (Snow Leopard):
http://clang.llvm.org/docs/BlockLanguageSpec.txtAs an Objective-C/Cocoa Developer:

A Stanford computer science class is available to the general public free online. The full 10 week course includes videos and pdf's. Online viewers of the Stanford course will see the same lectures as the on-campus students, but will not receive credit for the course.
23 videos around a hour each and 17 pdf docs.
see it, download it (with iTunes) @ http://deimos3.apple.com/WebObjects/Core.woa/Browse/itunes.stanford.edu.2024353965.02024353968
I'm going to Train a monkey to bring me 8 alphabet blocks and when each time he brings me 8, I will give him a bannana. Each time I will use the blocks in order he gave them to me as my password. Then, when my clients call in and tell me their password got hacked and ask me "What the F, do you guys have monkeys running that place or what?" Yes, yes we do, asshole.
Thanks Austin...
There are some great books out there to help you learn the iPhone SDK, Objective-C and Cocoa. Here's a link to a few of the best: Link