Monthly Archives: February 2011

How to Automatically Download TV Shows as Soon as They’ve Aired (or Turn Your PC into a TiVo) [How To]

Video content is readily available online for you to download, but the download process isn’t always as simple and automated clicking a button on a TiVO or DVR. Fortunately, with a little set up and some help from a few great tools and BitTorrent or Usenet, you can turn your computer into a TiVo-like downloader. Here’s how to set them up. More »

Find Out Why Gmail’s Priority Inbox Marked That Message as Important [Gmail Tip]

We’ve been fans of Gmail’s Priority Inbox feature ever since it launched, but it was sometimes hard to tell why Gmail marked a message as important. It turns out, you don’t even need to leave the inbox view to find out. More »

Skin Diving Tips

Skin diving is a great underwater activity and a viable alternatie to scuba diving especially if you haven’t applied for a license. However, skin diving is just as risky and dangerous as scuba diving. Here are some tips for a more safe and enjoyable skin diving experience.

For starters, make sure that you are a good swimmer. Practice on your community pool or nearby beach if you have to.

Learn to equalize the pressure in your ears. This will prove very useful since pressure levels are different as you go deeper into the water.

Have a medical check up if you wish to pursue skin diving as a regular sport. Do not attempt to dive if you have any ear, nose or throat sickness.

Always have at least one companion with you. Follow the one-up-one-down buddy system. Make sure that someone is watching the other as he dives deep into the water.

Avoid wearing goggles and ear plugs. Ear plugs can cause damage to your ear drums while goggles can injure your eyes as the water pushes them against your eyes.

Avoid stagnant or polluted water to prevent yourself from acwuiring skin, ear, eye or gastrointestinal infection.

Make Money in Your Spare Time Doing Simple Online Tasks [Money]

Yes, many "online jobs" promising quick riches and little effort are really scams. While the tasks below won't make you rich, they can earn you a little pocket money on the side—and these days that can make a big difference. More »

Make Your Own Printed Circuit Boards [Electronics]

If you have ever had a project where you custom designed a circuit, you know how useful it would have been to develop a PCB (Printed Circuit Board) based on your design. Doing it commercially can get expensive fast, so why not do this at home? More »

An Introduction to Categories (Part 2 of 2)

Using Categories to enhance models, and get rid of those pesky compiler warnings

When using Core Data, our model classes are always generated. What happens if we wanted to add a couple utility functions to one of these generated classes? Yep, they would be discarded the next time we auto-generated our model classes. As we discussed in our previous categories post (, adding a category on one of these generated classes would enable us to add those utility functions in without them being erased when we generate the core data models.

For example:
Say we created a Model object called Person, and added two NSString attributes called firstName and lastName. If we had populated our Core Data base with several Person objects, and then went to retrieve them, we would have an unsorted array. What if we wanted them to be sorted based on their names? One of the ways to accomplish this could be to implement a function called compareByName: that will return an NSOrderedResult. We can use this utility function to sort that array of Person’s.

Given a Core Data generated class from a model object called Person, we are given a file and it’s header of the form

//Person.h #import @interface Person : NSManagedObject { }   @property (nonatomic, retain) NSString *firstName; @property (nonatomic, retain) NSString *lastName;   @end ------------------------------------------------------------------------ //Person.m #import "Person.h"   @implementation Person   @dynamic firstName @dynamic lastName   @end

To add our category, we create an NSObject file of the name Person+Sorting.m, making sure that you check the create header file option.
As in the previous tutorial, change the files to actually be a category, and add in our new sorting function.

//Person+Sorting.h @interface Person (Sorting)    - (NSOrderedResult)compareByName:(Person *)person2;   @end ---------------------------------------------------------------------------------------- //Person+Utility.m @implementation Person (Sorting)   // Returns an NSComparisonResult caseInsensitiveCompare by lastName, and if that is the same, then by firstName - (NSComparisonResult)compareByName:(Person *)person2 { 	NSComparisonResult result = [self.lastName caseInsensitiveCompare:person2.lastName]; 	if (result == NSOrderedSame) { 		return [self.firstName caseInsensitiveCompare:person2.firstName]; 	} 	return result; } @end

As you can see, I added in some code that first compare’s the Person objects based on their last name, and if those are equal compares them on their first names.

Now to use this category, all we have to do is add

#import "Person+Sorting.h"

to any file where we use Person, and we will be able to use that compareByName: function.

NSError *error = nil;   NSFetchRequest *request = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Person" inManagedObjectContext:managedObjectContext]; [request setEntity:entity];   NSArray *results = [managedObjectContext executeFetchRequest:request error:&error];   //Turn those unsorted results into a sorted array NSArray *sortedPersons = [results sortedArrayUsingSelector:@selector(compareByName:)];   [request release];

There are of course other ways to get back sorted results from core data, but this is just one of the ways.

Getting rid of some compiler warnings
Another use of categories is to get rid of those pesky compiler warnings, when you call a function that is in the same file, however it is just lower down in the file.
The following code does not cause a compiler warning because the function we are calling comes first:

@implementation PersonViewController   - (void)loadPersonObjects { 	NSLog(@"function that comes before."); }   - (void)viewDidLoad { 	[super viewDidLoad]; 	[self loadPersonObjects]; } @end

However if for some reason, like you want certain functions clumped together at one spot in a file, and you have viewDidLoad at the beginning, then something like the following would give a compiler warning.

@implementation PersonViewController #pragma mark - #pragma mark View lifecycle - (void)viewDidLoad { 	[super viewDidLoad]; 	[self loadPersonObjects]; }   #pragma mark - #pragma mark Load from Core Data Functions //Other functions that load from core data also…. //.…. //.…. - (void)loadPersonObjects { 	NSLog(@"function that comes after."); } @end

To get rid of that compiler warning you can create a category on the current class in which you declare all the functions that are giving you warnings. You can do this at the beginning of the .m file after all the #imports, and before the actual @implementation of your class. The reason to do this is because you don’t want other classes calling these private classes, so you don’t want them in the header file, but you do want to get rid of the warnings. The following code snippet shows an example of fixing the warnings in the above class.

@implementation PersonViewController (__PRIVATE__) - (void)loadPersonObjects; @end   @implementation PersonViewController #pragma mark - #pragma mark View lifecycle - (void)viewDidLoad { 	[super viewDidLoad]; 	[self loadPersonObjects]; }   #pragma mark - #pragma mark Load from Core Data Functions //Other functions that load from core data also…. //.…. //.…. - (void)loadPersonObjects { 	NSLog(@"function that comes after."); } @end

Hipmunk Flight Search Brings the Excellent Webapp to iOS [Downloads]

We’ve taken a look at the Hipmunk webapp before and found it to be one of the most usable and agony-free flight searches on the web. Today they’ve brought that same search to iOS with some smart features. More »

CueThat Adds Netflix Movies to Your Queue from Any Web Page [Downloads]

All Browsers: Say you’re reading an article, tweet or review of a movie online and want to add it to your Netflix queue. With CueThat, all you need to do is select the movie title and hit the bookmarklet or extension. More »

How to Open Two Instances of an Application in OS X [Mac Tip]

Whether you want to look at two PDF pages side-by-side or you want two Twitter accounts open at once, sometimes OS X requires a separate instance of an application to be open. Here’s how to do it with a simple Terminal command. More »

How to Backup Everything on Your iOS Device Without Jailbreaking [Video]

Mac OS X: iTunes backs up your iOS device’s settings each time you sync, but it doesn’t even come close to backing up the device in its entirety. If you want a complete backup of your device, you can do it easily with an application called PhoneDisk and the wonderful command-line utility rsync. More »

WP Like Button Plugin by Free WordPress Templates