Posts Tagged “iPhone”
Apart from how powerful and flexible NSArray in Objective-C is, there are times that you need to sort many arrays throughout the projects.
The standard way of sorting arrays in Objective-C is to use one of:
- sortedArrayHint
- sortedArrayUsingFunction:context:
- sortedArrayUsingFunction:context:hint:
- sortedArrayUsingDescriptors:
- sortedArrayUsingSelector:
(See the official documentation)
But what if all you need is just a simple sort, available in different classes and across many projects?
Using sortedArrayUsingSelector:, for example, will need you to type in something like this as many times as you want to sort an array:
NSArray *array = [[NSArray alloc] initWithObjects:
@"Sally", @"Jake", @"Alex", @"Tim", @"Tammy", nil];
NSArray *sortedArray = [array sortedArrayUsingSelector:
@selector(caseInsensitiveCompare:)];
To make your life easier, Apple has made categories available for you to simply extend the functionality of a any class (NSArray in here) visible to the entire project. As you might wonder, you don’t even need to have access to the source code of the class you are extending.
Getting Started
To keep things clean an tidy, add a new Objective-C class to your project (File > New File…) and call it Categories. Make sure you create the .h file too.

Adding a new Objective-C class in Xcode
Then replace the interface with this code:
@interface NSArray (NSArraySortExtensions)
- (NSArray *)sortAscending;
@end
And the implementation with this code:
#import "Categories.h"
@implementation NSArray(NSArraySortExtensions)
- (NSArray *)sortAscending {
return [self sortedArrayUsingSelector:
@selector(caseInsensitiveCompare:)];
}
@end
Now go back to your class, where you want to use sorted arrays and first import the newly made class:
Now you can easily sort an array by sending a very short message to NSArray:
NSArray *array = [[NSArray alloc] initWithObjects:
@"Sally", @"Jake", @"Alex", @"Tim", @"Tammy", nil];
NSArray *sortedArray = [array sortAscending];
or even:
NSArray *array = [[[NSArray alloc] initWithObjects:
@"Sally", @"Jake", @"Alex", @"Tim", @"Tammy", nil]
sortAscending];
You can add more methods to the category and make NSArray even more powerful.
With the emergence of the iPad, there are many trends changing and many ideas developing around an old but finally well-developed phenomenon: the tablet computer.
Although I am somehow late giving my opinion on the subject, I think it is worth the try.
One of the areas cloud computing can be very useful and extremely capable is on the thin clients. Despite the fact that definition of a thin client nowadays is quite different than few years ago (take iPad and compare it to any of the “revolutionary” J2ME enabled devices) they are still far less capable than conventional computers, i.e. laptops and desktops.
iPad (as a good example and so far the best in the segment) is fairly powerful by itself and offers decent performance in doing resource-intensive tasks like 3D game rendering. But there are times that its processing power and storage capacity is not sufficient for certain tasks. You might say, well turn to a more powerful computer then. The price of such move could be sacrificing the super cool and useful features like ultra-portability and modern human user interface of the iPad.
Learning a new language along with news development tools is quite exciting and challenging at the same time. You have to go through most (if not all) basic stuff and make sure you’re not bringing any old habits to the new language.
For instance, after years of manual memory management in C and other languages, Java gave us the gift of garbage collection (for a price, though). Now jumping on the Mac (and more excitingly iPhone) development band wagon, brings up old C nightmares.
But it doesn’t need to come with nightmares at all, if you have the right tools to learn the language. Call me old fashioned but I always prefer books and ebooks for the starters. Then I’ll move to the official documentations and keep Google and stackoverflow when I’m stuck.
So far I am happy with 3 books in particular.
Now I’m in the very begining of what seems to be a long but fun road. Let see if it ends up in an AppStore top 10.
Few days ago I found a neat application that although tiny (almost 600KB!) changes the way you work with your iPhone/iPod.
Personally I was a bit irritated that I can’t access my files on my iPhone as easy as drag&drop. Now it is very easy to keep some files in my iPhone and even being able to access it by “Finder” (a jailbroken iPhone app).
Just download it from DiskAid Website and install the tiny DMG the Mac way! Voilla!

When you open the application it recognize your device in few seconds and shows the home folder.
Well, it is not exactly the home folder, it is ~/Media which is all you need to play with files securely.
It is also possible to copy files to you iPhone/iPod which makes it even better.
To download files it is just a simple drag&drop or choose the first item in the toolbar “Copy to folder” to select the destination folder.
Let me mention that there is a Windows version too so everybody can enjoy. It is a pitty that Linux is not supported although I’m sure Linux geeks will do (or already done) something about it.
To upload files I just created a new folder “DATA” to keep miscellaneous files separately. Then in any PC/Mac with DiskAid installed I can access to my files.

I’m not sure if Apple will reveal some new feature in the new version of iTunes for iPhone 3G but for the time being it is a nice tool.