“Hello World” for Dummies… – iOS
“Hello World” again. This is an introduction to iOS development for newbies. This tutorial explains briefly how to start developing an iOS application. As Android development explained before, these tutorials will continue with “native” development which means you need to be familiar with Objective-C and Swift programming languages.
Everything starts with Xcode, which is the official IDE for developing iOS applications and it runs only on Mac OS. So, please download the latest version of it.
It is no matter if you want to develop application for iPhone, iPad, Apple Watch or Apple TV; you can use Xcode for all.
Open Xcode and select “Create a new Xcode project” on welcome screen. After this, you need to select the type of your project. “Single View App” is enough for our first tutorial. Then, type your app name, organization name and identifier. When you create your project, you will see the general info about your application such as version no, app name, developer specialities etc. We will introduce this page later in another tutorial. Let’s focus on “Hello World” now.
There are many files on the left side of the screen, as you can see such as .h and .m files. In Xcode, your view files are created with .xib extension but at first, a storyboard is created automatically and your view is in it. There is ViewController architecture in Xcode development which allows you to connect and to implement logic to views.
You can see the code by selecting the files in left bar. Open Main.storyboard file, open library (there is a button at top-left for Xcode10) and add a “Label” in page. You can place label by dragging.
After dragging label, run project with “Play” button at top-right. You will see a “Label” text on screen. If you want a static text, you can set it from the right-bar options. Also you can change type, color, etc. from here.
But if you want to change it with code, go on. You need to reach this label view from view controller, so you need to initialize it. Select “assistant editor” button at top-right as marked below, select ViewController.h file, now you can see view and code together. Drag label with right-mouse-button into the code and type a name for this variable.
When you import something to .h file, you can reach it from .m file, that’s why we pull it from view file to .h file. Click on “standard editor” button to dismiss the second window and select ViewController.m file to edit.
Basically, in iOS lifecycle, viewDidLoad method runs after your view loaded and we are going to change label text in this method. You can touch text of label by calling .text in Obj-C and set it with a String.
_helloLabel.text = @"Hello World";
Now run your project and see the change.
©Coffee Break Codes – “Hello World” for Dummies… – iOS