iOS Open Source : Circular Rotating Menu
CDPieMenu is an open source project that provides a configurable, circular control for menu selection. The look is similar to the rotating hardware control on the original iPod.

In the screenshot above I’ve set the control to contain 10 images, each the same (white arrow). The control handles the UI from layout of the images to momentum and image selection (when the wheel stops rotating). CoreGraphics is the engine behind the drawing of CDPieMenu.
Continue reading this post »
Overview of iOS Application Directories
iOS applications have a limited number of directories available for writing content, the design intent is to ensure application security. This post will give a quick run down of the folder locations available in an iOS application and their intended use.
Documents Directory – ApplicationHome/Documents
The Documents directory is the primary location to save user and application related content. This directory and its subdirectories, are backed up when a user does a sync with iTunes. This is directory is also the repository for iTunes file sharing content.
The code below shows how to check for and print the path to the Document directory:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES); if ([paths count] > 0) NSLog(@"Documents directory: %@", [paths objectAtIndex:0] );
Tracking Down Exception Errors With objc_exception_throw
When an application throws an exception, there is debug information shown in the console – below is the output in the console for an NSInvalidArgumentException:

Although helpful, depending on the size of your application, it may take quite some time to find the offending code. One way to better track exceptions is to catch them, as shown in this post Try, Catch and Finally. However, wrapping every potential condition is not always practical. There is another way to track down exception errors.
Remove Debug Code For Release Build
When it’s time to remove debug code and log messasges from your application, it’s straight forward if you follow a few simple steps during development.
First, wrap debugging code in a block similar to the following:
#ifdef DEBUG // Debug code here... #endif
From the Edit Scheme dialog select the Run tab. In the Info tab, set the Build Configuration to Debug. By the way, when you create a new project, Debug is the default value, so you can skip this step if you have not previously changed the value.
Continue reading this post »
Count The Number of Words in a String
Here’s a quick way to count the number of words in an NSString object. The trick is to use the character set whitespaceAndNewlineCharacterSet which will look for spaces, tabs and newline characters.
- (NSUInteger)wordCount:(NSString *)str { NSUInteger words = 0; NSScanner *scanner = [NSScanner scannerWithString: str]; // Look for spaces, tabs and newlines NSCharacterSet *whiteSpace = [NSCharacterSet whitespaceAndNewlineCharacterSet]; while ([scanner scanUpToCharactersFromSet:whiteSpace intoString:nil]) words++; return words; }
If you have another way to reach the same result, please post a code sample.
Twitter Specific Keyboard – UIKeyboardTypeTwitter
In a series of previous posts I wrote about the integrated Twitter support that was introduced in iOS 5. If you are creating a custom control such as a UITextField or UITextView, there is a keyboard type specifically designed for writing tweets – the keyboard includes the characters @ and # on the primary view (no tapping necessary for a secondary keyboard view).
The image below shows the new keyboard:
How Many Days Are In The Current Month
If you ever need to determine how many days are in the current month, here are a few lines of code to get you there.
Calling the rangeOfUnit method in the NSCalendar object, you specify both a small and large calendar units. In this case, a day unit within a month unit. With that information in hand, check the length of the returned range to determine how many days in the month:
// Use today's date NSDate *today = [NSDate date]; // With a calendar object, request the day unit of the month unit NSRange dayRange = [[NSCalendar currentCalendar] rangeOfUnit:NSDayCalendarUnit inUnit:NSMonthCalendarUnit forDate:today]; NSLog(@"There are %d days in the current month.", dayRange.length);
I ran this example on April 4th, 2012, here is the output:
2012-04-04 21:42:33.816 Sandbox[4862:f803] There are 30 days in the current month.
If you know of another way to get the same information, feel free to post a code example.
Check If App Is Running On An iPad
Although you can use something like this – Get iPhone Device Name, Unique Device Identifier (UDID), OS and Model – to check if your app is running on an iPad, there is a much easier way.
Check the userInterfaceIdiom property of the device to get the information you need:
Continue reading this post »
Register File Types to Associate File Extension with an App
If you would like other applications to open your app based on a file type, you can register your document request in the application plist file.
Include the CFBundleDocumentTypes key, which is an array of dictionaries, where each entry defines information about the file type(s) your app supports.
Let’s look at a typical definition:
Continue reading this post »



