Separate and Append Strings in Objective-C

May 31, 2010

You can parse a string field into an array using the following code. In this example I am separating this string by ” ” or where there are spaces.
NSArray *array = [string componentsSeparatedByString:@" "];

If you wanted to take the array you built in the prior command, and join them together and separate the items by a “,” here is one example.
NSString *string = [array componentsJoinedByString:@","];

If you want to append string1 and string2, you can use the following code and the value will be stored in string3.
NSString *string3 = [string1 stringByAppendingString:string2];

Thanks for checking out my code example, and I plan to do many more, Dayton.


iPhone 3GS vs Nexus One in 3D game test

February 25, 2010

I was just checking out the video here were they ran a 3D game fps test on a iPhone 3GS and also on a Google Nexus One phone, and the iPhone 3GS was between 1.5x and 2.0x faster.

Engadget Artcle


Reachability in iPhone OS 3.0 with 1 line of code

January 24, 2010

In iPhone OS 2.0 I used this:
if ((([NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://www.google.com/"]]!=NULL)?YES:NO) == NO) {}

In iPhone OS 3.0, they deprecated stringWithContentsOfURL, so I rewrote this as:
if ((([[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:@"http://www.google.com/"]]!=NULL)?YES:NO) == NO) {}

Then inside the {} of this IF statement, I display a UIAlertView.

The benefit to this code is you do not need to know if the device is in Airplane Mode or if the WiFi antennae is turned ON or OFF. Also, I would recommend deallocating or using autorelease to free up memory for the NSString.


iPhone apps in Xcode without IB

November 6, 2009

I just finished listening to the Mobile Orchard podcast and Dan interviewed Jack Behrens. Jack talked about building iPhone apps and debugging them without using Interface Builder. How this makes your app more responsive and use fewer resources on the iPhone.

Jack Behrens article:

Mobile Orchard podcast