iOS Application Hello World
User Rating: / 8

No doubt, iOS takes leading positions on the market of mobile systems; therefore, Hello World application - first app that developer creates on the new OS - will be designed for iPhone and iPad.
Apple iOS is the most popular mobile OS today. Apple sold more than 410,000,000 iOS devices, and there are more than 1,000,000 applications in AppStore. In order to design even the smplest application for iOS, we need some theory, some kind of preparation. Lets begin with the developer suit.
Development environment for Mac OS and iOS is called xCode and can be launched only on Apple computers. Environment includes:
  • Compiler
  • Simulator
  • Cocoa and CocoaTouch libraries (frameworks for Mac OS and iOS respectively)
  • Instruments (powerful debug tool)
  • Interface Builder (allows to graphically design application interface)
  • On-line and off-line help
  • System of hints and help
It is not all features of xCode, however, for beginner even such number of components may seem more than enough.
It's necessary to mention MVC (Model – View – Controller). Apple follows Model - View - Controller structure in its applications and encourages developers to do so. Sense of MVC is as follows: algorithm of application's work is created separately from algorithm of application's design (view), and these two parts are combined by the algorithm of controller. Advantages of such structure are in that two groups may work on two main parts of application separately, and changes in one part do not affect another one.
So, lets begin. I expect reader to be familiar with basics of Objective-C and Cocoa Touch and basic work with xCode. First that we will do is to imagine, what do we want from device. In order to make it simple, our task will be to create blue screen with button "Make me say "Hello" ". After we touch the button, text “Hello world” will appear. Simple, but success will not be achieved in two strings of code.
Lets "code". Open xCode and create new project. Lets name it HelloWorldArticle. Follow screenshots. We create universal app - the one that will be available on iPhone and iPad at the same time. In this article we create app for iPhone; you should create iPad app by yourself as home task. Information about creating an application will be gained the best way only after you create this app without any help.
1. Background. Find file in the left ViewController_iPhone.xib (contains file of interface - xCode Interface Builder). Click on the "screen of iPhone", choose tab in the right Attributes Inspector, find parameter Background, and change background color to blue. Quite easy.
2. Button. Find button among visual objects in the right bottom. Drag it to the «iPhone». Use "corners" to change its size, so as it may contain entire text. Change only Title atribute on «Make me say «Hello World» ». Place button.
3. Text. For this purpose we would use Label object. Drag it from the right bottom and place it above the button. Change atributes: Text on «Hello, World», Color on more contrast one (for example, green), Drawing -> Hidden – check box.
4. First launch. Lets see, what does our app on this stage. Click "Run" button, choose iPhone simulator. There is blue background and button that can be pressed. Well done! All that we should do now, is to make Hidden parameter in Label change every time we press button. Lets do it.
5. Outlets and Actions. Outlets and actions are used to connect interface elements with code. We create outlet for the label in order to have access to it in code. We create action for button in order to handle act of pressing it. Simple and easy.
  • Action. In double view mode (Assistant editor – switcher in the right up) open interface file and file ViewController.h (file of View Controller header). pressing Ctrl button, drag button to the file. Blue line appears; release. In the menu name action «ButtonPressed». Confirm action. Now in the file ViewController.m (file View Controller implementation), ButtonPressed method appears.
  • Outlet. Lets do the same "drag" with the Label. Create outlet and call it Label. in the file ViewController.m write down string: @synthesize Label; after the beginning of implementation. This way we say, how we would access our label. Now we must write only one command.
6. Algorithm. All that we should do, is to write command to label "change your hidden parameter to opposite, when button is pressed". For this purpose we just write in the ButtonPressed method following string: Label.hidden = !Label.hidden;
7. Well done! Run!
Now, when we tap the button, text appears and disappears. Application successfuly announces "Hello" to the World.
I have only to say few words about the following fate of apps. There is only one way to AppStore, and it goes through Apple censors. Official developer sends app to company, where it is checked and is allowed to be in the Application Store. After that, app is available to all, who wants to buy it.
So, we created application on the most popular mobile OS in the world. I hope, this article became the step in your carier of developer.
Good luck in the next projects!
By Dmitry Bogatov, MAN Ukraine,
BookNewsPractice SearchPartnersAbout
Підтримка та дизайн: Могильний С.С. Шаблон: Joomla Templates by BuyHTTP Joomla Hosting