Introduction: Creating Your First IOS App

Looking around this site, it occurred to me that there weren't many 'ibles on programming the iOS platform, so I thought I'd fix that deficit. This is a simple "hello, world!" app for iPhone (or iPod Touch, or iPad). This 'ible will also serve the purpose of helping others become familiar with the IDE known as Xcode, which is what you need if you want to program for the iOS platforms.

Step 1: Get Xcode

If you already have Xcode, you can skip this step.

If you want to develop apps for iOS, you need the SDK, which is provided with Xcode. Xcode only runs on Mac OS X (yes, Apple is doing that on purpose), so if you are running a windows (or linux, or pretty much any non-Mac OS X) operating system, you have a couple options:

1. Get a mac, by far the easiest, but it can be rather expensive.

2. Find a friend with a mac, if they are nice, they'll let you use it for programming, you should warn them, however, that programming takes a long time.

3. Give up, Those are your legal options, there are some other options that are either illegal, or are in the gray area (meaning it's debatable whether or not it is illegal), so I am not mentioning them, you want to know them, find them yourself, I won't be responsible.

Now that's settled, onto the IDE. Go to the mac app store (available in mac os x 10.6.8 and later) and search Xcode. It's the first option, click on it. Download it, it's a lengthy download, ~4 Gb, so if you have a slow internet connection you may want to consider doing something else while it is downloading.

Step 2: Open Xcode & Set Up the Project

1. Open Xcode.
2. Go to File>New>Project.
3. Click on Single View Application and click next.
4. Name it Hello World!
5. Decide whether you want it to be an iPhone app, an iPad app, or universal (I will be doing iPhone)
6. Make sure use storyboards and Use Automatic Reference Counting are checked
7. Click Next
8. Navigate to where you want to save the file and click Create

Step 3: Write the Code

You will be doing the programming in the ViewController.m file, but it doesn't hurt to look at the other files. The MainStoryboard.Storyboard file is the UI, we'll deal with that later. The appDelegate is what is called on startup, in this tutorial, we will be leaving that alone.

Ok, time to start programming.

1. Open up ViewController.h

2. Between @interface ViewController : UIViewController and @end add the following code: 
@property (strong, nonatomic)IBOutlet UILabel *label;
This is the label that will show the Hello World text. If an empty circle appeared next to the line of code, then you wrote it right

3. Go to ViewController.m

4.  Under @implementation ViewController add @synthesize label; and in the viewDidUnload function add [self setLabel:nil];

5. In viewDidLoad, add the following code: self.label.text = @"Hello World!";

6. That completes the programming for now

Step 4: Connect the UI

Next We'll deal with the UI.

1. Open MainStoryboard.Storyboard

2. Find a label and drag it onto the view (if this sounds confusing, refer to the picture)

3. Resize the Label to your liking by clicking and dragging on the squares in the corners of the label

4. Go to the Attributes inspector (if you are not already there, refer to the picture)

5. Make sure it is centered, and choose the font and size you want. I will stay with the system font, but scale it up to size 25

6. Open the Assistant Editor, it should open ViewController.h, if not, you need to change it to ViewController.h (again, refer to the picture)

7. Remember that circle I told you about earlier? Click and drag from it to the label you just added. If you did it right, the circle should be filled

Step 5: Run the App

That's it! Hit the Run Button and if you did everything correctly, your app will say Hello World!
Pat yourself on the back, you just wrote your first app.

Step 6: Have Some Fun by Adding Things Programmatically

To make it a little more advanced, we are going to add everything programmatically.

1. Delete the label we added to the UI as well as all the code we wrote up to this point.

2. Open ViewController.h and add the Following code between the @interface ViewController: UIViewController and @end:
@property (strong, nonatomic)UILabel *label;
Notice how a circle did not appear this time? That's an indication that you did it correctly

3. In ViewController.m add @synthesize label; right beneath @implementation ViewController and add [self setLabel:nil]; in the viewDidUnload function.

4. In the viewDidLoad function add the following lines of code:
//Define where the label will be displayed
self.label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 100)];
//Define the text to be displayed
self.label.text = @"Hello World";
//Center the Text
self.label.textAlignment = UITextAlignmentCenter;
//Programmatically add the label to the view
[self.view addSubview:self.label];

5. Hit run and admire your handiwork, you've completed your first iOS application

Comments

author
Pradeepmishra made it!(author)2016-12-25

Bad

author
littledesire5 made it!(author)2016-11-06

I am able to make it

http://www.littledesire.com

KTZkZuxJ.png
author
ari_bama17 made it!(author)2016-08-31

Hi Guys, before starting with the development it's important to spend a good amount of time in defining the concept of the app, to avoid it to fail.

For help you can download this free ebook : http://try.goodbarber.com/ebooks/apps-for-beginners-define-your-concept

author
mobitsolutions made it!(author)2016-06-28

It's good news for all developers. http://goo.gl/aIKYTw

author
Grep+Scott made it!(author)2016-02-11

Good for new developers but It is very easy to develop iOS apps by using new language by Apple called "Swift". It have many builtin features that you can use in your application.


Domain Age Checker
author
IshaA1 made it!(author)2016-01-25

I am a beginner in iOS app development.This article is very helpful to me.Thanks for sharing this.

http://www.atees.in/

author
Firebolts made it!(author)2015-11-27

So you cant get the program on anything but a mac... u cant even get it on a ipad...etc

author
itsmarkkessler made it!(author)2015-11-24

This was the best step by step tutorial for learning of how to start building iOS apps. I hope it makes more easy for developing first iOS app.

http://www.mobilepundits.com/

author
Hola90 made it!(author)2015-11-24

Wow this is amazing tutorial for learners like me. I also found another website to create your own app. They have different options to create your own app. Click here to see in action.

author
Stevee07 made it!(author)2015-09-22

This is Very Good Tutorial for iOS Mobile Application Development Ideas.. Useful for Me Thanks..

author
carlmal made it!(author)2012-08-20

Would be great if you could include how to get the app onto your device. Thanks for the instructable.

author
thinkdunson made it!(author)2015-04-08

guys, the reason they don't allow you to put apps on your phone is because, then you could put them on any iPhone. this would circumvent the app store. the whole point of the app store is that the only way to get an app on an iPhone is after it has been tested by apple to make sure it works and does what it says it will. it's quality control. ultimately, it's about making sure everything on an iOS device "just works". i for one fully support a business model that allows them to make money while ensuring a quality product. it's the one thing that sets apple products apart. it makes them more expensive, yes, but it's worth it to many people.

author
A-Nony-Mus made it!(author)2012-08-20

Unfortunately (and I learned this the hard way), you need to be a part of the paid developer program (US $100/year) in order to put the app on your device.

author
MHaakansson made it!(author)2012-08-22

For your own device, connected with your iTunes, you don't need to be in the developer program - just connect the device for sync.
But if you want your app in the AppStore, you need to be in the program.
best regards
Martin

author
Zaphod+Beetlebrox made it!(author)2012-09-15

Is it jailbroken?

author
A-Nony-Mus made it!(author)2012-08-22

I had to join the program to put it on my device, but if you'd post an 'ible on how to do that, I'd love to be proven wrong.

author
StefyB made it!(author)2015-02-09

As an iOS app developer, I suggest you to develop apps with mobile app development platforms. It will save your lots of time as well as you will get plenty of handy features.

I generally use Configure.IT because it provides good features compared to other platforms such as automatic coding, App preview facility, .PSD file export for UI design and many more. You can view the detailed list here:

http://www.configure.it/features/mobile-app-configuration/

author
Jimmy64 made it!(author)2014-01-14

we are ready to help to create your first iOS app. if you need any help, please visit www.taoteapps.com & learn more.

author
andrewmazer13 made it!(author)2013-12-04

Hi,


Thanks for sharing this app for iphone development, Iam going to try build a new app.


Thanks,
Andrew

author
jerry30 made it!(author)2013-10-27

Hi,

I am a iphone Developer,with 1month exp, this Tutorial is very helpful for me,thanks for sharing this

author
nathanjohnson made it!(author)2013-09-13

I am an iPhone developer and according to me It's a really nice post..It will definitely helps all the iPhone developers. Checking the worth of the website: http://www.appschopper.com

author
jhomer made it!(author)2013-07-12

I hate apples power-based monopoly. You shouldn't have to use a Mac just to legally use their dev software

author
gumption made it!(author)2013-06-05

Thanks for the simple introduction to iOS app development.

FWIW, an alternate approach to the proposed substitution above would be to add another label.

Since I'm using iOS 6, UITextAlignmentCenter is deprecated; a post on StackOverflow (http://stackoverflow.com/questions/12792999/what-are-good-alternatives-to-uitextalignmentcenter-in-ios-6) suggested using NSTextAlignmentCenter instead ... and for backward compatibility, to use the following:

#ifdef __IPHONE_6_0
# define ALIGN_CENTER NSTextAlignmentCenter
#else
# define ALIGN_CENTER UITextAlignmentCenter
#endif

I added the following line to ViewController.h (below the @property declaration for label):

@property (strong, nonatomic)UILabel *label2;

and added the following line in ViewController.m (below the @synthesize label; line):

@synthesize label2;

After adding the preprocessor macro proposed in the StackOverflow, and using the code provided above (substituting "label2" for "label" in the added statements), my viewDidLoad method appears as follows:


- (void)viewDidLoad
{
    [super viewDidLoad];

    // from before:
    self.label.text = @"Hello World!";

    // using a Y coordinate of 200 instead of 0 for label2
    self.label2 = [[UILabel alloc] initWithFrame:CGRectMake(0, 200, 320, 100)];
    self.label2.text = @"Goodbye";
    self.label2.textAlignment = ALIGN_CENTER;
    [self.view addSubview:self.label2];
}

author
gumption made it!(author)2013-06-05

Note that the second part of Step 4 is no longer necessary (or supported).

viewDidUnload
Called when the controller’s view is released from memory. (Deprecated in iOS 6.0. Views are no longer purged under low-memory conditions and so this method is never called.)

author
imjohnbo made it!(author)2013-03-28

Great tutorial. But, when I click run, the iOS Simulator screen comes up with a white screen, no label. I've followed your directions except for not using the viewDidUnload function, as it's deprecated in iOS 6.1. Any ideas? Thanks!

author
A-Nony-Mus made it!(author)2013-03-28

I work on a MBP, so I only have 15 inches of screen size. Ever since apple announced the new iPhone screen size, I have to scroll up and down, like I would with a page, if I want to see the entire app.

author
ThunderBow98 made it!(author)2013-03-04

Um just wondering but what programming language did you use in this tutorial? Thanks

author
A-Nony-Mus made it!(author)2013-03-05

It was written in objective-c, an object oriented version of c.

author
iceng made it!(author)2012-09-20

I did the  Hello World ! 
Now, can I mess with the RF output to unlock my car, Only My Car.
I don't want to sell or provide the Xcode to anyone.
Is this possible ??

A

author
championx5 made it!(author)2012-08-20

Quick question, I'm currently making my own RPG with RPG Maker VX Ace and i'd like to know if there was anyway i could make it into an app?

author
Ragevortex made it!(author)2012-08-29

A-nony-mus
Nice Iabble for an app introduction mon

Championx5
In your case I recommend Construct 2 http://www.scirra.com/construct2
its originally free and when your "app" is ready then you may decide to use either of the licenses they offer. In my case I just upload the finish product as a web app to my server for testing up til i'm happy with it.

Cheers and happy hunting/programming/iabbling or whatever...-ing :)

author
A-Nony-Mus made it!(author)2012-08-20

Don't know, never heard of that software before now. I know that unity has a way of making iOS apps, so it wouldn't surprise me if this did.

author
hojijoon made it!(author)2012-08-22

very nice thank you bro!

author
zacker made it!(author)2012-08-20

all that just to say Hello World? whats it take to make an actual app like these photo editing apps and such?

author
A-Nony-Mus made it!(author)2012-08-20

Apple has tons of sample code if you want to take a look at that and get the idea of the size of an average program.

author
remendab made it!(author)2012-08-20

That is not all that much work - really. With much power comes much responsibility, meaning that there are many small things required just to get up and running, but once you are, running that is, the next steps are not that much more complex

author
zacker made it!(author)2012-08-20

...like baby steps.. lol Thanks!

author
jschmukendorf made it!(author)2012-08-19

Very nice introduction to writing an app! This could be the road to riches for someone with a good idea an a willingness to learn.

Thank you!!

author
Fugitive_Bill made it!(author)2012-08-19

I'm not rich enough for 'i' stuff. I'll have to learn how program Android clones!!
Who's with me, lot's I'll bet!, erm a few maybe?!

author
MMI+Studios made it!(author)2012-08-19

Read my post below... You don't need an "i" machine to develop for iOS... The author was more than a little inaccurate by telling everyone there is no "legal" way to develop for iOS without a Mac machine...

author
perfo made it!(author)2012-08-19

Hello, thanks for the ible.
Can the Xcode be run on an iphone or IPad? With a big screen and keyboard attached it could be an option I'm guessing. Second question is once you've written this app, how do you publish it? Say you have one of those super expensive MAC and wrote this app then how do you get it on to your Iphone and run it?
I'd like to see a simple app with a button that did something, i.e. turn the LED on and off just to see how you would interface with the iphones hardware.
Thanks again fella.

author
A-Nony-Mus made it!(author)2012-08-19

Unfortunately, to test the apps you write on your devices, you have to be a member of the paid developer program (US $100/year).

author
perfo made it!(author)2012-08-19

Oh...no wonder it wasn't obvious. Thanks for replying.

author
HandySun made it!(author)2012-08-19

First of all, I have been modifying and making my own code for years now, and this makes sense to me. But from the perspective of someone who has never worked this code, it will make no sense at all to them.

I really suggest if you plan on doing more of these, you get WAY more in depth or just don't do it at all. You're just going to confuse and frustrate people who are new to programming for this reason.

If your instruction was pointed at people who know coding, then why on earth would you do something this basic? In this case it would have been better to make a simple button that turns the camera light on.

author
iFirefly made it!(author)2012-08-19

Hey I look forward to reading this through and hope I can pick up some skills, so thanks in advance!

I did want to let everyone know that there is an alternative to Apple hardware so you can use cheaper Windows computers and run Mac OSX to program your iOS apps.

Its called "Hackintosh" and if you do an Internet search on that term alone, you will find the information necessary to determine which computer processor, video card and memory requirements to succeed. I have never done it myself, but have read several sites' worth and it seems fairly straightforward.

author
TimPayne made it!(author)2012-08-19

Nice! Thanks for creating this Instructable.

author
MMI+Studios made it!(author)2012-08-19

Umm... There is a big inaccuracy in your ible... You should probably do a little more research before telling people such things... There are several LEGAL Windows based mobile development solutions that INCLUDE iOS... If you google "iOS development on Windows" the very first search result will be this: http://maniacdev.com/2010/01/iphone-development-windows-options-available/

It's a list of iOS dev solutions for Windows. I use one on this list, Titanium Studio by Appcelerator and it's great... It's an Eclipse based IDE... Also, if you have Flash of Flex CS5.5 or higher you can use the built-in iPhone Packager... Marmalade is another good solution: http://www.madewithmarmalade.com

It's actually quite easy to build a mobile web app using HTML5, CSS3, and JavaScript and package and deploy it to iOS... Regardless of platform, legally... The only part you NEED OS X for is to submit the app... But there are services that can do the submission for you...

author
MMI+Studios made it!(author)2012-08-19

I actually do most of my development in OS X myself... Not really using Xcode though... I primarily just program HTML5/CSS/JavaScript (along with a healthy dose of XML and JSON) in my editor of choice (SublimeText 2) and then package them for iOS... Don't really see much need to use a full featured IDE unless working on large enterprise project working with a nice sized team of developers... Another app worth taking a look at is Construct 2 by Scirra... It's for rapid HTML5 game development... You can take the output of that and package it for mobile, including iOS...

author
gbeltrao made it!(author)2012-08-19

If you know HTML5 there's an online app that allow you to simulate iOS based devices and save it as an app for iPhone, iPad, etc. http://www.electricplum.com/studio.aspx

author
gbeltrao made it!(author)2012-08-19

Correction: It's a desktop application, not an online app as I posted.

About This Instructable

274,287views

602favorites

License:

Bio: I am an Apple Developer in College ultimately pursuing a masters in robotics. If you would like to take a look at my apps, all ... More »
More by A-Nony-Mus:How to use the camera in your iOS programCreating your first iOS appRat-trap powered vehicle
Add instructable to: