Xcode 4.5 how to pick storyboards at launch

This is a great question.

What you need to do is,

  1. Select your current 4/4s storyboard, go to File, duplicate, then give it an iPhone 5 specific name. Make sure that Target and your app name is checked.

  2. Next you have to select the scenes in your storyboard and in the Attributes Inspector change the size to Retina 4 Full Screen. This allows you to rearrange everything for this display.

  3. Finally in application didFinishLaunchingWithOptions paste the following code with the storyboard name you gave for your 4 inch storyboard.

    - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
    if(UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone){
        UIStoryboard *storyBoard;
        CGSize result = [[UIScreen mainScreen] bounds].size;
        CGFloat scale = [UIScreen mainScreen].scale;
        result = CGSizeMake(result.width * scale, result.height * scale);
        if(result.height == 1136){
            storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard_iPhone_5" bundle:nil];
            UIViewController *initViewController = [storyBoard instantiateInitialViewController];
            [self.window setRootViewController:initViewController];
    return YES;

If anyone don't get how to do step 1, do as below.

  1. Go to Project directory and copy paste the MainStoryboard.storyboard and rename new storyboard to say MainStoryboard5.storyboard.

  2. Add this new storyboard MainStoryboard5.storyboard in project (in Xcode) by right clicking Project and clicking Add Files to ....

  3. Now we have two storyboards in xcode.


You may have to use 'Product > Clean' for this to work after you have done all the above.


What are the benefits of using Storyboards instead of xib files in iOS programming?

A Storyboard is:

  • A container for all your Scenes (View Controllers, Nav Controllers, TabBar Controllers, etc)
  • A manager of connections and transitions between these scenes (these are called Segues)
  • A nice way to manage how different controllers talk to each other
  • Storyboards give you a complete look at the flow of your application that you can never get from individual nib files floating around.
  • A reducer of all the "clutter" that happens when you have several controllers each with it's own nib file.

I have been using Storyboards for awhile now and the ONLY downside is that you can't target iOS 4 or below. Storyboards only work on devices running iOS 5 or better. Other than that, the benefits are many and the downsides are non-existent IMO.

The best tutorial I have seen is Ray Wenderlich's

Also, if you are a member of the Apple Developer program, check out last years WWDC session on Storyboards (iTunesU), it is awesome.

Another great one (also on iTunesU) is the latest Stanford iOS Application Programming course.


Read a .txt file from a server?

I need only read a txt file at my server on my X-Code project.

And thats the way:

NSString* myFile = [NSString stringWithFormat:@"http://www.yourdomain.com/yourfile.txt"];

    NSString* myFileURLString = [myFile stringByReplacingPercentEscapesUsingEncoding:NSASCIIStringEncoding];

    NSData *myFileData = [[NSData alloc] initWithContentsOfURL:[NSURL URLWithString:myFileURLString]];

    NSString *returnedMyFileContents=[[[NSString alloc] initWithData:myFileData encoding:NSASCIIStringEncoding] autorelease];    

    NSLog(@"%@", returnedMyFileContents);

Can i have a single NSMutableArray in my multiple views application?

If you are having multiple views in your application, and in that case you want to have a variable accessible to every view, you should always create a Model/Data(singleton) class and define the variable in it. Something like this :


@interface DataClass:NSObject{

NSMutableArray *arrGlobal;


@property(nonatomic,retain) NSMutableArray *arrGlobal;




@implementation DataClass

@synthesize arrGlobal;

static DataClass *instance =nil;

+(DataClass*)getInstance {


if(instance==nil){ instance = [DataClass new];


return instance;


Now in your view controller you need to call this method as :

DataClass *obj= [DataClass getInstance];  
obj.arrGlobal = arrLocal;

This variable will be accessible to every view controller. You just have to create an instance of Data class.


How to set iPhone UI View z index?

UIView siblings are stacked in the order in which they are added to their superview. The UIViewhierarchy methods and properties are there to manage view order. In UIView.h:

-(void)insertSubview:(UIView*)view atIndex:(NSInteger)index;
-(void)exchangeSubviewAtIndex:(NSInteger)index1 withSubviewAtIndex:(NSInteger)index2;
-(void)insertSubview:(UIView*)view belowSubview:(UIView*)siblingSubview;
-(void)insertSubview:(UIView*)view aboveSubview:(UIView*)siblingSubview;

The sibling views are ordered back to front in the subviews array. So the topmost view will be:

[parentView.subviews lastObject];

and bottom view will be:

[parentView.subviews objectAtIndex:0];

Like Kolin Krewinkel said, [parentView bringSubviewToFront:view] will bring the view to the top, but this is only the case if the views are all siblings in the hierarchy.


Show hidden files Mac OS X 10.7 Lion and 10.8 Mountain Lion

To enable hidden files/folders in finder windows:

  1. Open Finder
  2. Open the Utilities folder
  3. Open a terminal window
  4. Copy and paste the following line in:
    defaults write com.apple.Finder AppleShowAllFiles YES
  5. Press return
  6. Now hold ‘alt’ on the keyboard and right click on the Finder icon (ON DOCK)
  7. Click on Relaunch
You should find you will now be able to see any hidden files or folders. One you are done, perform the steps above however, replace the terminal command in step 4 with:
defaults write com.apple.Finder AppleShowAllFiles NO