RSS
 

Archive for the ‘Apps’ Category

Core Data Objects in Wrong Sections

Posted on Monday, October 18, 2010
18 Oct

NSFetchedResultsController is a really handy class. Use one of the default Core Data templates in Xcode and you’ll very quickly have a nice list of managed objects in a table view. With a few more lines of code you can get the NSFetchedResultsController to group your objects by sections. You do this by specifying a key-path in the class’s constructor method but there is another step that if overlooked will cause some confusion.

In a sample app I’ve created a food table that lists food in categories.

FetchedResultsController method grouping sections using a key-path:

- (NSFetchedResultsController *)fetchedResultsController {
	if (fetchedResultsController != nil) {
		return fetchedResultsController;
	}
 
	// Create and configure a fetch request with the food entity.
	NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
	NSEntityDescription *entity = [NSEntityDescription entityForName:@"RWFood" inManagedObjectContext:managedObjectContext];
	[fetchRequest setEntity:entity];
 
	// Create the sort descriptors array.
	NSSortDescriptor *nameDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
	NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:nameDescriptor, nil];
	[fetchRequest setSortDescriptors:sortDescriptors];
 
	// Create and initialize the fetch results controller.
	NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:@"category" cacheName:@"Food"];
	self.fetchedResultsController = aFetchedResultsController;
	fetchedResultsController.delegate = self;
 
	// Memory management.
	[aFetchedResultsController release];
	[fetchRequest release];
	[nameDescriptor release];
	[sortDescriptors release];
 
	return fetchedResultsController;
}

Screenshot of Food sample app in wrong order.Save and quit the app a few times and you’ll see the objects seem to be in the wrong sections. If you look closer you’ll see that the objects are actually sorted in ascending name order. On looking at the code, it seems this is exactly what we asked the program to do! After some testing it also seems to show up more often if the table is a grouped one.

As per the docs, after you specify a key-path to group each section with you also need to make sure the first sort descriptor is sorting this key-path. Add a sort descriptor and everything will work as expected.

Revised fetchedResultsController method with missing sort descriptor:

- (NSFetchedResultsController *)fetchedResultsController {
 
	if (fetchedResultsController != nil) {
		return fetchedResultsController;
	}
 
	// Create and configure a fetch request with the plant entity.
	NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
	NSEntityDescription *entity = [NSEntityDescription entityForName:@"RWPlant" inManagedObjectContext:managedObjectContext];
	[fetchRequest setEntity:entity];
 
	// Create the sort descriptors array.
        NSSortDescriptor *typeDescriptor = [[NSSortDescriptor alloc] initWithKey:@"type" ascending:YES];
	NSSortDescriptor *nameDescriptor = [[NSSortDescriptor alloc] initWithKey:@"name" ascending:YES];
	NSArray *sortDescriptors = [[NSArray alloc] initWithObjects:typeDescriptor, nameDescriptor, nil];
	[fetchRequest setSortDescriptors:sortDescriptors];
 
	// Create and initialize the fetch results controller.
	NSFetchedResultsController *aFetchedResultsController = [[NSFetchedResultsController alloc] initWithFetchRequest:fetchRequest managedObjectContext:managedObjectContext sectionNameKeyPath:@"type" cacheName:@"Plants"];
	self.fetchedResultsController = aFetchedResultsController;
	fetchedResultsController.delegate = self;
 
	// Memory management.
	[aFetchedResultsController release];
	[fetchRequest release];
        [categoryDescriptor release];
	[nameDescriptor release];
	[sortDescriptors release];
 
	return fetchedResultsController;
}
 

Pub Darts now with Instructions!

Posted on Thursday, July 29, 2010
29 Jul

Pub Darts iconWhen I first launched Pub Darts last March, I got many great positive messages from people who love throwing darts at their boss’s picture! I also got much negative feedback from people who found the throwing mechanism difficult or not as intuitive as I thought it was. Therefore adding instructions to version 1.1 was very important to avoiding those 1 star reviews!

However due to work commitments it has had to sit on the back-burner but with the recent release of the iPhone 4, I couldn’t help but update Pub Darts with gorgeous high resolution artwork. I also managed to add in some instructions, make a new icon, fix a few bugs, allow games to save themselves when you quit and completely redo the shadows to be more ‘iPhone-like’. This free update can be grabbed immediately from your iPhone by updating in the App Store application.

More updates are coming soon. Feel free to suggest some features you’d like to see. If you’ve yet to experience Pub Darts on your iPhone, grab it for free now.

Pub Darts Screenshot Pub Darts Screenshot

 
 

Take Audi iPad Magazine for a Drive

Posted on Friday, July 23, 2010
23 Jul

It’s such a good feeling when something you’ve worked so hard on gets unleashed onto the App Store. It’s even more of a great feeling when you find out your app has already broken into the Top 50 chart of most-downloaded free apps. Achieving more than 15,000 downloads in the first two weeks, I’m immensely proud to have been the lead developer of Audi Magazine for iPad. Download it for free now!

As a team, we spent considerable time making sure the rotating mechanism worked just right and making sure the app loads in less than half a second. I’m looking forward to starting on the next issue soon!

 
No Comments

Posted in Apps, iPad

 

iPhone App: Throw Darts at your Boss

Posted on Tuesday, March 31, 2009
31 Mar

Pub Darts screenshot Pub Darts screenshotHooray. My iPhone game, Pub Darts is in the App Store. It’s a slick dartboard game with the added bonus of being able snap your boss/greedy banker and throw darts at their image. Just don’t let them catch you ;-)

Buy it now for only £1.19 ($1.99). For a short time only it’s now completely free! Grab it now.