Objective C tutorial: Hello world

This tutorial helps you get started with Objective-C. It explains what you need to write your first Objective-C program. It starts with the basics: you will learn where you can find and download the tools needed, how to install these tools and it will take you all the way to building and runing your code. If you have never written an Objective-C program before this is the place to start. We have created this article, so you can get started with Objective-C, and move on to our sms examples. If you are already familiar with Objective-C, you can jump directly to one of the following SMS projects.

Objective-C sms examples:

Objective-C send sms with the HTTP rest api (code sample)
Objective-C send multiple sms with the HTTP rest api (code sample)
Objective-C schedule sms with the HTTP rest api (code sample)
Objective C receive sms with the HTTP rest api (code sample)
Objective C delete sms with the HTTP rest api (code sample)
Download the latest Objective C sms api library from Github

What is Objective-C

Objective-C is a programming language, that was developed by Google. It is similar to a natural language, like English. It is used to talk to a computer. The major difference between a natural language and a programming language is that, programming languages have a more rigorous structure, to help the computer understand it better.

What is a Objective-C 'hello world' program

The Objective-C hello world program is the most simple program you can write. It simply prints out the sententce: Hello world on the computer screen. The Hello World program is the first program developers write in any programming language.

How to write your first program in Objective-C

To write your first program in Objective-C:

  1. Check prerequisites
  2. Setup Xcode
  3. Create new project in Xcode
  4. Write Hello World program in Objective-C
  5. Use NSLog(@"Hello, World!"); for printing
  6. Run your Objective-C Hello World program
  7. Check the output
  8. Fix errors if needed

Prerequisites

Here is what you need to get started. To write your first computer program in Objective-C, you need a Windows computer, the go language and example code presented below.

  • Mac computer
  • Xcode
  • Ozeki Hello World example project

Download and install Xcode (Video tutorial)

In this video, you will learn how to download the Xcode coding environment to your mac computer. It will start with opening the app store and will end with the opened program. You will learn how to find the app and how to begin the installation procedure. This video is great because it contains all the information needed to complete the procedure. It is only a little longer than 1 minute, so you will have no problem understanding it.

Create your first project in Xcode

After Xcode has been installed, you need to open it, and create a console project. The console project is the most simple project you can create.

Create a new project (Video tutorial)

In this video, we present to you how you can create a new Objective-C project in Xcode. It will start with naming your project and will end with a blank coding panel. You will learn how to customize the Objective-C project before creating it. The video is only 28 seconds long but it is very detailed, so you will have no problem understanding it.

Write your first 'hello world' program in Objective-C

The first program you write in any programming language is the 'Hello world' program. The sole aim of this program is to print the term 'Hello world' to the computer screen. In this example the program consists of few lines of code: The fith line: NSLog(@"Hello, World!"); prints the text.

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        NSLog(@"Hello, World!");
    }
    return 0;
}
	

Code 1 - Your 'hello world' program in Objective-C

Write your Hello World program in Objective-C (Video tutorial)

In this video you can see how to write your first Hello World message in Objective-C in the Xcode environment. It will start with a blank coding panel and will end with a working Hello World application. You will see all the code lines you need to create. This video is only a little longer than 1 minute, but it is very easy to follow. Don’t waste any more time. Let’s start coding!

Run your first 'hello world' program

How to run your code (video tutorial)

In this video, you can see the process of launching your code. It will show you which button you need to click in Xcode to run your first Objective-C Hello World program. This video is easy to follow because it is only 12 seconds long.

What happens if you make a mistake in your code

If you make a mistake, when you write your instructions in Objective-C, you will get a Syntax error. The computer will highlight the line with error in red, and it will tell you why didn't it understand the instructions. To correct the mistake you need to go back to the text editor and modify the program. Programs say they "fix the error" when they correct mistakes.

In the code below we will create a mistake intentionally by not putting a semicolon after the Hello World line. You will see, how the computer reacts, how we fix the error, and how we run the computer program successfully.

What is syntax error?

Syntax error means I don't understand. If you talk to somebody in English and he does not understand what you say, he will reply with "I don't understand". If you talk to a computer in Objective-C and the computer does not understand what you say, he will reply with "Syntax error".

How to handle a syntax error in Objective-C?

In the code below we will create a syntax error intentionally by not putting a semicolon after the Hello World line. You will see, how the computer reacts, how we fix the error, and how we run the computer program successfully.

How to fix errors in your code (Video tutorial)

When you are coding, making errors is inevitable In this video, we will show you the steps of debugging or correcting errors. It will show you a code with an error at the beginning, and the fixed runnable code at the end. This video is only 30 seconds long, but very detailed. You will have no problem following the steps. In the video, we are using the Xcode environment to debug an Objective-C code.

Summary

Now that you have read the in-depth guide above, you have made your first step in becoming an Objective-C software developer. This program may seem simple, and it may not do much, but this is how great things start. Don't forget that every programmer starts with the basics so be patient and the hard work will pay off. The next step in your learning journey will be creating an HTTP request.

Objective-C is the main programming language when it comes to software development in OS X and iOS. This language offers dynamic runtime and object oriented capabilities, so investing time in Objective-C is definitely a good choice. Ozeki SMS Gateway works well with Objective-C, so these codes can be used while working with the program. It also has to be mentioned that Ozeki SMS Gateway offers you the ability to route SMS messages between various endpoints and gives you the ability to control the SMS messages as they go through the system.

Continue the learning journey on Ozeki's tutorial page, where more information can be found about topics like SMS sending and deleting in Objective-C.

Now the only thing to do is to download Ozeki SMS Gateway and let the work begin!

"

More information