Programming for iPhone. What is needed to develop iOS applications


  1. Programming language. What you need to know to write applications for iOS.
  2. Do you need a designer, interface developer, or someone else?
  3. Official part: developer certificate.
  4. Necessary equipment for comfortable development.
  5. The eternal question: AndroidOS or iOS?
  6. What needs to be done today?
  7. Creating a new project.
  8. Compilation. What is it and why is it needed?
  9. Run on the simulator.
  10. We print “Hello, world!”
  11. What standard views are there in iOS?

Programming language. What you need to know to write applications for iOS

Programming language(wikipedia.org) is a formal symbol system designed for recording computer programs. A programming language defines a set of lexical, syntactic and semantic rules that define the appearance of the program and the actions that the performer (computer) will perform under its control.

Perhaps the question I asked in the title of this part is quite complex. I can answer it simply - Objective-C. If I stopped there, I would be wrong. I would say that Objective-C is the bare minimum. Recently there was a conference from Yandex - YET, at which one of the reports was devoted to what programming languages ​​a developer should know. The answer was something like this: “He must learn new and new programming languages ​​constantly, without stopping at any one in particular.”. I completely agree with this. By learning new programming languages, you learn new approaches and programming methods. Therefore, to write applications for iOS, you need to know Objective-C, but it is also advisable to know other programming languages ​​so that your code is good, efficient, and flexible.

If you are not a programmer yet, then I advise you to start with the C language. Download the book by Kernighan and Ritchie ( or better yet, buy it) about the C language, read it, do everything that is suggested to you, and after that I would advise you to move on to Objective-C. If you already understand how to write programs, you are ready to easily answer the questions - “What are data types? What is a variable? What is a function or method? What is a link and a pointer? What's happened "include”?” , you know C or C++ or Java or C#, then you are ready to write your first application for iOS.

You also need to know the basics of OOP and design patterns. The list can probably be continued, but I’m hardly ready to claim a qualitative explanation of these concepts. Yes, unfortunately, Objective-C is not the language with which you can start your programmer journey. But if you like and want to create, then it’s time for you to run to the store, buy books and start your developer journey.

Do you need a designer, interface developer, or someone else?

Another, no less simple question. If you are a programmer and know how to write console programs and want to start writing applications for iOS, then at the initial stage you do not need such a person. If you have an iPhone || iPad || iPod touch If you're familiar with iOS, then you don't need a front-end developer. In general, Apple has such a document - HumanInterfaceGuidelines. IN this document describes where and what interface element should be used. Therefore, at the initial stage you can do without third parties. In general, the iOS SDK provides enough opportunities for painting the application interface, so you don’t have to draw any buttons or multi-colored texts, gradient fills, etc. in PS. Later, we will create the first project, in which we will get acquainted with all the stages of creating the “Hello, World!” application.

However, you need to understand that when serious projects begin, applications that you want to publish in the AppStore, it will be more difficult for you without a designer and developer. The difficulty can manifest itself at different stages - either during application development, when you spend hours searching for the necessary image or sitting and creating in PS, or after you publish the application and start receiving comments from our beloved users who will complain about your poor design free application. I encountered similar problems at both stages. After receiving lousy comments on the AppStore, I wanted to abandon my application, which by the way is free, and forget about ungrateful users. However, the usefulness of the app itself to me, as well as many other users, made me swallow those angry comments and continue developing the app. About three months ago, I started developing an application together with a designer who tells me what to insert and where, what color to choose, where and what picture to draw, and this, I want to say, is quite convenient. Therefore, I still advise you to start using the services of designers at some point in order to receive good feedback from users. And remember - iOS device users want to see good application design, even if its functionality suffers.

Official part: developer certificate

You've probably already heard a lot about some kind of developer certificate. Now I will try to bring you up to date - why it is and whether you need it right now. A developer certificate is a file, just like any other certificate. This file gives you Apple company after you go through all the stages of registration in the system iOS (MacOS) Developer (Enterprise) Program.

What will having it give you? this file and registration in one of the above programs? The answers to this question are overwhelming. Therefore, I will only say about the most important things (everything described below is given to you for exactly one year):

  • testing your applications on your devices (although this seems to be hackable and can be done without a certificate)
  • access to the developer forum on the Apple portal (although there is a community on StackOverflow.com, where you can find an answer to your question much more quickly)
  • ability to download beta versions (and of course current ones) of iOS and Xcode
  • the ability to install beta versions of iOS on your device
  • ability to publish an application in the AppStore
  • the ability to link up to 100 devices to your account, thereby allowing these devices to install beta versions of iOS, test your applications (not yet published in the AppStore) and much more illegal things
  • the opportunity to show off to your friends that you are an official iOS application developer

If you decide that you need such a certificate, then be prepared to part with $100 ($300 for Enterprise), send a fax to the USA, enter the details of your bank card (attention! Yours, exactly yours), and finish reading this chapter.

So, let's go.

  1. Follow this link http://developer.apple.com/programs/ios/
  2. Click on Enroll Now
  3. We read the flood carefully and move on – Continue
  4. Here we have 4 points:?a. Do you want to create new Apple ID for Apple Developer Program?b. Do you want to use existing Apple ID?c. Are you already registered as a simple developer, and now you want to become an official developer with all the benefits described above? d. You are already a member of the iOS or Mac Developer Program and want to link another program to your account
  5. Friends, next you need to go through a couple of steps to fill out your personal information. I don’t remember exactly what’s there anymore. If you have any questions, ask them in this topic, I will answer everything as best I can.
  6. You were given a link to a .pdf file that you need to fill out and fax to Apple.
  7. We print it and fill it out (very carefully and carefully).
  8. We send a fax to the Apple office in the USA. (Be careful that your fax does not fall into the wrong hands, because there you indicate the bank card number and CVV).
  9. We wait N number of days (weeks) for Apple to process your request.
  10. We receive a letter congratulating you on signing up for the program and losing a hundred bucks. Hooray!

After successfully completing the quest you will have access to http://developer.apple.com/membercenter/. Perhaps a review of that page either requires a separate article or requires a Google/Yandex search.

Well, friends, let's move on to the remaining issues on the agenda.

Necessary equipment for comfortable development

If you have seriously decided to start developing applications for iOS, then I highly recommend immediately purchasing a computer/laptop with MacOs. The cheapest option is a Mac Mini, or something used. If you are a student and are going to carry equipment with you - Macbook Air. If you have a lot of money and want a powerful, versatile laptop - for gaming, complex computing tasks and programming - Macbook Pro. If you want to take desktop computer– iMac or Mac Mini. For development, any computer in any existing configuration will suit you. Screen size is at your discretion. I personally am now sitting in front of a Macbook 13” and a Mac Mini 17”. I'm happy with both displays. If so, you can always connect external monitor to the laptop.

Don't forget that sooner or later you will need an iPhone, iPod or iPad. You don’t have to rely only on the iOS simulator, which is distributed in the same package with Xcode. Always test release versions on devices. Or - look for testers (responsible and conscientious).

If you are not ready to spend so much money on new equipment, then you can try installing a Hackintosh on your computer.

The eternal question: Android or iOS?

It is possible that this question should have been asked at the very beginning, but it is still located at the end of this article. Are you sure you want to try your hand at mobile development, but don’t know which mobile platform to choose? I can't answer this question for you. But I know one thing - if you want to develop applications for iOS, then you must love Apple products and operating system iOS and MacOs. You may ask - why is this? The answer is simple - you must love what you do, you must create. Only then will you be able to develop a truly cool and useful product. Only in this case will you enjoy learning Objective-C and iOS. I think this is very important. If you have similar feelings towards Apple products, then feel free to go into the field of iOS development. If you think - I know Java, but I don’t know Objective-C, but I like iOS better than AndroidOs - then choose iOS. No, but what did you expect me to start praising Android OS?

I also like the iOS sphere for its app store. Everything there is beautiful, correct, and there is very strict moderation of applications. The dump of applications that is now in Android OS is simply terrible, both for users and worthy developers.

What needs to be done today?

Today you must decide: when you start developing applications, will your current experience be enough to learnObjective- C, do you have necessary equipment, and the most important desire?

Hello, world.

Checking readiness

Let's move from theory to practice. For practical lesson you will need Xcode 4.2 with iOS SDK, preferably a developer certificate, knowledge of C, C++, Java or Objective-C (well, maybe knowledge of other languages ​​will do) and, finally, a desire to start writing applications for iOS. If you are missing something, for example, a developer certificate, then the article will still be relevant to you. In any case, it seems to me that every iOS device user should be interested in taking a look at the inner workings of application development.

Creating a new project

Go. Click on the Xcode icon. A window similar to this will open:

Select the item “Create a new Xcode project”. In the next window, select the project type. We need: “iOS – Application – Single View Application”.

Click Next. We will see a window with the following content:

Let me explain the input fields:

  1. Product Name – The name of the new project – you can enter any name, but I advise you to use names identical to mine, because I will periodically refer to them.
  2. Company Identifier - Your company identifier - you can fill it out as you wish.
  3. Bundle Identifier – a unique identifier for your application. This field can be edited later.
  4. Class Prefix – a prefix that will be assigned to the names of all classes that you create in the project. I left the field empty ( "XYZ"– this is just a hint).
  5. Device Family – on what types of devices the project can be installed. You can choose one of three options: iPad/ iPhone/ Universal. Their purpose is obvious. If you can't decide right now whether you need to create a universal app, you can choose any of the other options. This can be corrected at any stage of the software life cycle.
  6. Use Storyboard – This is related to creating a user interface model. Added with iOS5, so that when using this horror, your application can only be installed on devices with iOS5 or higher.
  7. Use Automatic Reference Counting is a new feature of the Apple LLVM 3.0 compiler - it automatically (almost) manages memory (monitors leaks, zombies and other horrors). I would say that for a beginner it is an ideal option. BUT – 1) not everything there is so automatic, 2) do you trust the compiler more than yourself?, 3) I recommend managing memory manually.
  8. Include Unit Tests – connect unit testing to the project.

You will see a window for selecting a category where the project will be placed. I just want to warn you that a folder with the name of your project will be automatically created in the folder that you selected, that is, there is no need to create an additional folder for a specific project.

We do not check the “Create local git repository for this project” checkbox. It’s better to connect our project to the code repository later if necessary.

Click “Create” and see a new window, the window of our workspace:

And so, we have created a project, some files have been generated, some windows are open.

Let's take a look at the files in the navigation menu:

  • files with the suffix “.h” are headers, where we will give descriptions of classes
  • files with the suffix “.m” are implementation files, where we will implement the previously described classes
  • files with the suffix “.xib” are files that describe the interface of a single application window

Compiling the project

Compilation -

  1. translation of a program into a language close to machine language and its subsequent assembly.
  2. translation of a program written in the source language into an object module (carried out by the compiler) and its subsequent assembly into a ready-to-use program module.
  3. translation of a program written in a source language and its subsequent assembly into a program in some machine-independent low-level interpreted code (as, for example, in the case of the Java language).

The compilation process consists of the following phases:

  1. Lexical analysis. In this phase, the sequence of characters in the source file is converted into a sequence of tokens.
  2. Syntactic (grammatical) analysis. The sequence of tokens is converted into a parse tree.
  3. Semantic analysis. The parse tree is processed to establish its semantics (meaning) - for example, binding identifiers to their definitions, data types, checking data type compatibility, determining the resulting data types of expressions, etc. The result is usually called "intermediate representation/code", and can be supplemented by a parse tree, a new tree, an abstract set of commands, or something else convenient for further processing.
  4. Optimization. Redundant commands are removed and the code is simplified (where possible) while preserving its meaning, that is, the algorithm it implements (including pre-calculated (that is, calculated at the translation phase) expressions, the results of which are practically constants). Optimization can be at different levels and stages - for example, on intermediate code or on final machine code.
  5. Code generation. From the intermediate representation, code in the target language is generated (including program linking).

More in simple language from me. At the lexical analysis stage, it is checked that all the characters in your source code are in the right order and related characters in the following stages will be considered as a single entity - a lexeme. At the parsing stage, it is checked that all lexemes are located in the correct order, in the right places, in the correct sequence. Finally, at the semantic analysis stage, data type matches are checked.

And so, when you click “Build project”, then first a lexical analysis of your code is performed, if it is successful, then parsing, and then semantic analysis. In Xcode, a certain lightweight process is always running that performs this function, thereby prompting the developer "on the fly". For example, if you did not put “;” or suddenly you equate int to a certain string of characters, then Xcode will underline the string with a red wavy line.

Running on a simulator

And so, let's try to launch our project, for which we have not yet written a single line of code personally.

To do this, let's look at the menu: Compilation scheme(she was assigned green color in my screenshot). A diagram is a certain configuration of a project. Xcode generates it automatically. Click on the line to the right of the project name (device name); if the device is not connected, it will say “iOS Device”. You will see a drop-down list with the following content:

In this list we select where our project will be installed: it can be either your device or a simulator. If you have selected the universal application type, you will be able to select the simulator type: iPhone or iPad. You can also select the operating system version for simulators (it is important to test the project on all versions of iOS on which the application can be installed). Since we are talking about the minimum version of iOS, we should also mention how to determine its minimum version? It's simple - if you use methods (features) that were added in the iOS version, for example, 4.0 , then the bar for the minimum required operating system rises to 4.0 . Let's lower the bar to 4.0 With 5.0 . To do this, turn to the menu: “Deployment target” (highlighted in blue in my picture). Select from the drop-down list 4.0 . Now let's go back to the menu: Compilation scheme. Our list now looks like this:

Select “iPhone 4.0 Simulator”. And finally, click on the arrow under which it says “Run”. IN “Information board” we will see the compilation process. After everything comes together successfully, the iPhone simulator window will open:

Now let's quickly go over the capabilities of the simulator.

  • You can simulate iPhone, iPhone Retina, iPad.
  • Simulate different versions iOS.
  • Take screenshots.
  • Rotate screens (portrait and landscape modes)
  • Shake
  • Simulate low memory.
  • Simulate a print server
  • Geolocation location
  • Multi-touch gestures (maximum 2 fingers)
  • Other

All this can be accessed from the simulator program menu:

A few words about the simulator. The simulator can only install applications via Xcode, they can be uninstalled directly from the simulator (just like on a real device), and it supports multitasking. But it also has many limitations, for example, you cannot install a certificate in the local application certificate store. But the main drawback is that it SIMULATOR, but not EMULATOR. That is, it just pretends that it is an iOS device, simply by rendering a similar interface ( program level). But the emulator does exactly what the device will do (at the physical level). What conclusion should be drawn? Be sure to test on a real device. I have had cases when it works on the device, but not on the simulator, and vice versa.

We print “Hello, world!”

I hope everything is more or less clear up to this stage. If not, then during the development process you will begin to understand more deeply.

This chapter was written in memory of Dennis Ritchie creator of the programming languageCand key operating system developerUNIX, and also as co-author of the book “Programming LanguageC» .

The purpose of the chapter is to decorate our empty gray screen. Great, let's go. We return to Xcode, select “ViewController_iPhone.xib” in the navigation menu. Next, select “View” from the list that appears. On the right, select “Attributes Inspector”. Here's what the window looks like for me plus additional comments:

Now let's add a UILabel. UILabel is the name of a class in the iOS SDK that allows you to display non-editable text on the screen. In general, all classes that allow you to display something have the prefix UI: UIView, UITableView, UITextView, UIButton,…. In the “Available objects for display” window, look for a line named Label. Once we find it, we click on it and drag it to our current screen view.

The blue dotted lines will help you center/calibrate the relative position of the mark. And so, select Label in the list of displayed objects, if not already selected, and see the item in the properties: Text. Let's write “Hello, World!” there. and press Enter. Here we have the text of the label changed and shrunk. Let's fix this. IN property categories let's choose "ruler""Size Inspector". There are fields:

  • x and y are the coordinates of the upper left corner of the label relative to the parent view, that is, the view where we placed the label - this is the View in our case.
  • width and height – the width and height of the edited object, respectively.

You can try editing these values ​​and observe the changes. You can also edit the position and size directly by moving the label (text) and pulling its frame by various “dots”.

Spend another 15-25 minutes playing around with the different properties in the different categories:

  1. Text alignment
  2. Font size
  3. Color, text shadow
  4. and etc.

Subsequently, we will return to them and I will explain the purpose of certain fields.

What standard views are there in iOS?

In the previous paragraph, I touched on the names of some classes responsible for the interface. The console itself UI and stands for User Interface. Here I will give, perhaps not a complete, list of available view types. Firstly, all the classes described below inherit from UIView, i.e. have the same properties and methods. Secondly, you can always create your own custom view. The list below:

1) UILabel – label – main purpose: displaying one or more non-editable lines of text.

2) UIButton – button – main purpose: a regular button, sends signals to objects, notifying that it has been clicked

3) UISegmentedControl – a button with segments – main purpose: a button with several active parts, you can determine which one was clicked

4) UITextField – text input field – main purpose: field for user input text

5) UISlider – slider – main purpose: a regular slider, helps to change any settings more intuitively

6) UISwitch – On/Off switch – main purpose: has two states – on or off, the purpose is obvious

7) UIActivityIndicatorView - activity indicator - main purpose: usually used to inform the user that the application is either downloading data or simply performing some calculations

8) UIProgressView – status (progress) indicator – main purpose: to display the state of completion of something

9) UIPageControl – switching between pages – main purpose: displaying the number of pages, displaying the current page

10) UIStepper (>= iOS 5) - +/- step controller - main purpose: also obvious

11) UITableView – table – main purpose: displaying a table is perhaps the most popular element

12) UITableViewCell – table cell – main purpose: displaying a row in a table, usually customizable

13) UIImageView – image – main purpose: displaying a picture or image

14) UITextView – text field (scrollable) – main purpose: displaying a large amount of text that can be scrolled.

15) UIWebView – web – main purpose: displaying a web page

16) UIMapView – maps – main purpose: map display

17) UIScrollView – scrollable view – main purpose: displaying several views that do not fit on one screen

18) UIDatePicker – date picker type – main purpose: ideal for entering a date

19) UIPickerView – drum selection type – main purpose: an alternative to the table when selecting an option

20) UIView – just a view – main purpose: obvious

21) UINavigationBar – navigation bar– main purpose: a panel in which the screen title and additional control buttons are displayed

22) UINavigationItem – UINavigationBar elements – main purpose: obvious

23) UIToolbar – toolbar – main purpose: displaying a panel on which buttons are placed to control the application

24) UIBarButtonItem – toolbar elements – main purpose: obvious

25) UIBarButtonItem (fixed and flexible space) – special toolbar elements – main purpose: change the distance between the buttons on the toolbar

26) UITabBar – tabbar – main purpose: helps switch between various unrelated screens

27) UITabBarItem – tabbar element – ​​main purpose: obvious

So, you purchased an iPhone or iPad. Wonderful devices, aren't they? Some time later the thought came: “shouldn’t I create a program for it that will conquer the world?” I'll tell you where to start.

The first thing you need is a computer with an operating system Mac system OS X. At least Mac Mini (cost from 20,000 rubles). There is no other way. As a last resort, you can install a virtualization system (VMWare, VirtualBox, etc.) under Windows or Linux, and install Mac OS X there (I will not describe the process itself - it has already been discussed many times on Habré).

Secondly, you need knowledge of English. At least within the framework of “translating with a dictionary” - after the first 2-3 books you will also improve your English (which never hurts) to the level of “fluent reading” technical literature" Translated books come out with a huge delay - six months to a year at least. And the majority do not appear in Russian at all. And most of the translated programming literature is impossible to read - people who are far from this topic translate it.

Get ready to buy the nth number of electronic books (you can also buy them in paper, but a: it will take a long time to ship; b: it will be more expensive). They cost approximately 25-80 dollars. Yes, it's expensive, but it's worth it.

Step 0: Necessary basis

You will primarily program for iOS in Objective-C. Objective-C is an OOP (object-oriented programming) superset of the C language. So you must know C. Required knowledge can be found in the book
David Mark, James Bucanek. Learn C on the Mac 2nd Edition

Step 1: Objective-C

Next, you need language knowledge Objective-C programming. An excellent language that is relatively easy to learn.
So, the basics of the language can be learned from books:
Scott Knaster, Waqar Malik, Mark Dalrymple. Learn Objective-C on the Mac 2nd Edition
or
Aaron Hillegass. Objective-C Programming: The Big Nerd Ranch Guide

The next book is rather a supplement to the previous ones
Matthew Campbell. Objective-C Recipes

The next thing you need to know for full-fledged OOP is design patterns. Ideally, it is highly advisable to read the book Gang of Four. Design Patterns. Next, a book about patterns in relation to Objective-C:
Carlo Chung. Pro Objective-C Design Patterns for iOS

Step 2: iOS SDK and iOS UI

iOS SDK is a development kit for iPhone, iPad and iPod. Without his excellent knowledge - nowhere.
iOS UI - user interface. Simply put, these are buttons, sliders, labels, etc., etc. – everything you see on the screen of your device. Naturally, this should also be known as “Our Father.”
First, you should read this book
David Mark, Jack Nutting, Jeff LaMarche, Fredrik Olsson. Beginning iOS 6 Development

Well, to top it off, you can flip through the appendix to the two previous books
Hans-Eric Gronlund, Colin Francis, Shawn Grimes. iOS 6 Recipes

The next book is very good - it deserves the title " complete guide on development for iOS." Unfortunately, the book is somewhat outdated, but this in no way detracts from its merits.
Joe Conway, Aaron Hillegass. iOS Programming: The Big Nerd Ranch Guide, 3rd Edition

The next two books are, so to speak, for improvement. Each of them is a collection of lessons and explanations of the intricacies of the iOS SDK. All this material can be found in scattered form on these Internets of yours, but in these books it is collected, sifted and sorted with special love.
iOS 5 By Tutorials, Second Edition
iOS 6 By Tutorials

Application: Games

The previous books will be enough for you to write simple applications for your mobile device. Complex ones you will write after huge amount practices. At some point you will want to write a game, and this knowledge will simply not be enough for you. To write games you will need many times more knowledge: mathematical basis, excellent knowledge of geometry up to three-dimensional, physical basis, basics of AI design and much, much, much more... But you will do this yourself. I will simply list a set of books that it is advisable for an iOS game developer to read.
Lucas Jordan. Beginning iOS 5 Games Development
Kyle Richter. Beginning iOS Game Center and Game Kit
Steffen Itterheim, Andreas Low. Learn cocos2d Game Development with iOS 5
Jayant Varma. Learn Lua for iOS Game Development
Mike Smithwick. Pro OpenGL ES for iOS
Sue Blackman. Beginning 3D Game Development with Unity
Philip Chu. Learn Unity 4 for iOS Game Development
Robert Chin. Beginning iOS 3D Unreal Games Development

Afterword

Do you think that after reading all these books you will become a Senior iOS Developer? No, no, no and no!
Once Steve Ballmer, becoming general director Microsoft Corporation, told who brings success to operating systems and platforms: “Developers! Developers! Developers! Developers!
I'll put it another way: what makes a developer a master? Practice! Practice! Practice! Practice!
No amount of knowledge outweighs practice. My personal advice: after reading all the books in my review from the first to “Beginning iOS 6 Development” inclusive, get a job as a junior developer in any company. For any conditions. For any salary. This experience is invaluable - you can’t get it from books.
Good luck!

Update: the review is intended for complete beginners and does not claim to be complete, infallible or the ultimate truth.

This article begins a series intended for beginners. I dare to hope that the level of presentation of the material will allow even people unfamiliar with programming to understand it. Let's start our story with a small lyrical digression. Applications for iPhone and iPad are written in Objective-C. This language was widely used at NeXT and came to Apple after the return of Steve Jobs. Currently, Objective-C is the main language for developing OS X and iOS applications.

In order to start programming for iOS, you will need Mac computer based on Intel processor and XCode development environment. If you don't have a Mac, it doesn't matter. Perhaps one of the described methods for solving this problem will suit you. We will focus on XCode 4 and iOS5.

Installing XCode

First, we will have to register on Apple's dev site. Follow the link and click on register. Click the Get Started button and complete the registration process. Everything is quite simple there, so I won’t dwell on this point. After registration, you will be sent an email with your Apple ID. Return to the Apple Developers page and use it to enter the secure area. In the DevCenters section, click the iOS link. As you can see, Apple offers you a ton of documentation, sources, and tutorials. This page has everything you need to get started with iOS development. At the very bottom there is a Download Xcode button that you need to click. Once downloaded, install Xcode on your Mac.

Getting to Know the XCode 4 Interface

To launch Xcode, go to your main drive and click developer>Applications.

Once Xcode has launched, select File>New Project, then Single View Application and enter HelloWorld as the Product Name. As a result you should see something like this

All your code and resources are organized into special folders, which are located on the left side of the Xcode window. The panel is called "Project Navigator" and contains all the elements of your program. Source code files have the extension ".h" and ".m". If you click on such a file, an editor with the code will open on the right side of Xcode.

Let's not dwell on the code for now. We will return to this issue a little later. If you look at top part screen, you will see several buttons related to your project. Let's study this panel in more detail.

The "Run" button starts your project. You can test your application and make sure it actually behaves the way you expect it to. The "Tasks" button stops the running application.

Using the Schemr button, you can select the target platform where your application will run. Here you can choose a simulator and debug the program on your computer, or run it on your iPhone (iOS Device) if you paid the $99 fee. The only advantage that this payment provides is the ability to run the program on a real device and host it in App Store. I would not recommend that you spend money until you have a normal program ready.

Breakpoints are a very useful thing. Using this button, you can mark lines in the source code, and when the program reaches the marked line during execution, the program will pause and you can view the state of the variables. This is a very powerful and widely used tool.

Click the "Run" button. You will see an emulator window with your project. As you can see, while it does not shine with functionality, it is just a blank.

Programming for iPhone - The first step

Enough beating around the bush, let's code something. The Project Navigator window contains source code files. Click on some .m file. Please note that some lines are colored green - these are comments that act as cheat sheets. In order not to get confused in the code, the programmer can leave hints and explanations for himself. To denote comments in the C language, the combination of slashes // is used. Everything on the line to the right of these characters is considered a comment. If you want to write a multiline comment, you can use the combinations /* and */ to indicate the beginning and end of a multiline comment.

Before we start writing the application code, I need to explain a few concepts to you with my fingers: OOP (Object Oriented Programming), MVC (Modal View Controller), ".h" and ".m" files. So... object-oriented programming involves dividing all code into so-called objects, within which data and the commands that process it are stored. An object in Objective-C consists of two files.h and .m. The file.h is called the header; it contains a “sketch” of the object - all data and names of command blocks (methods) contained in the object are listed. The .m file is called the implementation file and it describes in detail everything that is indicated in the header; this is where all the program logic is programmed.

MVC (Model View Controller) is something that separates the code and the interface that the user sees. Model is the user data and the data you show to the user. View is the user interface and code that provides communication between View and Model. The concept of MVC may seem too abstruse to you now, but over time you will see that this approach really simplifies the life of a programmer. This concept implies the following order of work: the programmer separately creates an application design template, where he places all the buttons, text fields and other important nonsense, and writes programs separately. Then it shows XCode which method (block of code) should be called in response to a particular user action and what name this or that control element has in the program text.

We develop a program design for iPhone

Let's start creating our application by developing the design. In the Project Navigator window, click MainStoryboard_iPhone.storyboard. As a result, XCode will launch the interface editor.

In the lower right corner you see a list of objects (Library) that can be used in your interface; in the central part the View window is displayed, which represents the layout of your program’s interface. The upper right window has several modes, which are switched using the icons located above the window. The figure shows the Attribute Inspector mode. Here you can change various attributes of the objects that make up your interface.

Let's drag a Label object from the Library window onto our window layout. Using the mouse, we will change the size of the object, as shown in the screen below. The inspector displays the properties of the Label object. Let's center the text by clicking on the corresponding icon in the Layout line.

Let’s delete the text in the Text field (the word Label was written there) and enter “Some String” there.

Similarly, add a button to the layout (Button object)

So, we have developed the design of our application. Nothing complicated, you can click the Run button and look at the work of your program in the emulator window.

Let's start coding

So, we have two visual components placed on the layout. We want the text in the line to change when the button is clicked. To implement this idea, we will need to access a row (Label object) from the program code and call a method (block of code) when the button is pressed.

Click on the "ViewController.h" file in the left panel. We are going to describe IBOutlet. IBOutlet connects our code to a visual object, such as a label or button. Change the code in the ViewController.h file to look like

#import @ interface ViewController: UIViewController( IBOutlet UILabel* label; //give our string the name Label } //this is the header of the method that will be //called in response to a button click- (IBAction) buttonClick: (id) sender; @end

This is all we need to write in the header file. IBAction allows you to connect a method to a user interface element, for example, in response to a button click, the program code we have written will be called.

So, we said that we will call the string with the text label and that the buttonClick method will be called in response to user action. Let's write the code for this method. Let's switch to the ViewController.m file in the project tree. After the line @implementation... add the code

- (IBAction) buttonClick: (id) sender( label. text= @ ”Hello from Mobilab. ru”; )

Note, if you copied this code, you will probably get an error when you run the program, most likely the problem is in the quotes. Delete them and enter them from the keyboard.

Let's figure out what we see here. We access the label object - a line of text on the screen. Since this is an object, it has various data inside it (which in OOP are also called object properties) and methods that can be accessed by placing a dot after the object name. The text property is responsible for the text contained within a string.

We've completed the coding, all that's left is to associate the label and buttonClick with the elements inside the design layout. Click on the MainStoryboard_iPhone.storyboard line in the Project Navigator window to switch to the interface designer. Then click on the “View controller” icon. Switch to connections mode in the inspector (last icon). Look, the label line has appeared in the Outlets area of ​​the inspector. This is the name that we specified in the ViewController.h file. Click the circle on the right side of the label line and drag it onto the Some Text line in the design layout.

Do a similar operation with the button. Click on the button with a circle in the “Received Actions” group, then click on buttonClick and drag it onto the button in the layout. As a result, a context menu will open, with which you can select when to call the method. You can, for example, call the code when the user presses the button, or when he releases it. There are many options. Select "Touch up Inside".

That's all! Save the project and click on the "Run" button on the top panel. If you did everything correctly, the emulator with your program should start. Click the button. The text in the line should change. That's all. The first lesson is over

The profession of a programmer is one of the most prestigious and in demand, that’s a fact. The software development industry has its niches. Of these, the fastest growing, and at the same time the most highly paid, is software development for mobile devices. As you know, it just so happened that, leaving their competitors far behind, three constant rivals took the lead. The trick is that one of these three is the undisputed leader, while someone always catches up.

In the mobile technology segment, Apple is undoubtedly the leader with its iPhone smartphone. At a presentation held in September, the Cupertino company demonstrated the 7th version of the mobile device. Along with it, Apple introduced a new version of the mobile operating system iOS 10. Now it is the most significant operating system in the world, like its predecessors. It follows that learning iOS development is the best investment of time and money.

Apple ecosystem

Today we will develop a simple mobile application for iOS. Of course, a native Mac is best suited for this. But if you're a Windows supporter or you simply don't have a Mac, you can install the macOS operating system under virtual machine on Windows. On the Internet, it will not be difficult for you to find a version of macOS specially tailored for PC, popularly called Hackintosh. Feel free to install it on a VMware virtual machine, VirtualBox - your choice. Let me warn you right away that the PC keyboard does not have some of the keys that are on the Mac keyboard, and many of their combinations cannot be pressed in Hackintosh. This pretty much spoils the mood. Otherwise, all the operations described below can be successfully performed on Hackintosh.

Required knowledge

To program in general and for iOS in particular, you need to know quite a lot. Mathematics and logic may not be needed at first, but they will be in demand later. Modern technology has eliminated the need for a programmer to have a thorough knowledge of computer architecture, but understanding basic mechanisms such as number systems, their conversion, the speed of subroutines or the efficiency of algorithms (big O) is necessary.

At a higher level, an iOS developer needs to have a deep knowledge of the macOS operating system and iOS itself. You also need to master the Apple programming language. Knowledge of Delphi, C++, C# or VB.NET will not help you much. Apple has its own ecosystem with its own languages: Objective-C and Swift. Of course, knowledge of C++ has never harmed anyone; programs and inserts based on it are found everywhere, even at Apple. But the most used by definition is Objective-C, simply because it appeared much earlier (in the mid-eighties of the last century), while Swift only two years ago (in 2014). Apple has high hopes for the new language and is investing heavily in it. Objective-C is used to support the old software, and the new one is written in Swift. So it's good for you to know both.

In order not to waste time, all these programming languages ​​can be learned under the strict supervision of teachers on the website.

Development Tools

As you know, the main developer tool for macOS and with it iOS is the programming environment Xcode. It includes tools for creating applications for Mac, iPhone, iPad, Apple TV, Apple Watch. All Apple platforms. Xcode contains Interface Builder, a code editor that supports everything modern means working with code. In addition, without leaving Xcode, you can test the application; if it is developed for an external device, then it can be run in an emulator.

The system includes emulators of all devices, new versions of which can be downloaded. In addition, Xcode contains graphical tools for analyzing application performance, including tools for diagnosing CPU load, storage usage (HDD, SDD and others), load on the graphics adapter (from the OpenGL side).

On September 13, a new, hotly anticipated version of the development environment 8.0 was released. Stable versions can be downloaded for free from the App Store. Alphas and betas are distributed by developer subscription. The eighth version includes: a new version of the Swift 3 language, the Swift Playground learning tool for iPad, a new version of Interface Builder, which has become faster and allows you to view the application layout on different platforms, without having to deploy the application itself to the simulator.

Xcode 8 can be used to develop applications for macOS Sierra, iOS 10, watchOS 3 and tvOS 10. All SDKs are available. New versions of operating systems began to appear consistently right after Apple’s presentation, which took place in early September.

Objective-C language

Let us briefly recall the basic information about the language. Objective-C is a compiled object-oriented programming language used for writing applications for Apple systems. It is a superset or, in other words, an add-on to C, inheriting from the latter syntax, data types, methods of monitoring the progress of program execution and adding to it the capabilities of object-oriented programming - a description of classes and methods.

As in C++, in Objective-C the central role is played by objects, which are associated with four paradigms: abstraction, encapsulation, inheritance, polymorphism. C++ is a strongly typed language, while Objective-C is weakly typed or has a dynamic data type system. Like Smalltalk, Objective-C sends messages to objects. This is an exceptional feature of dynamic languages ​​because the type of objects is checked at runtime rather than at compile time.

The description of the Objective-C language takes up more than one voluminous volume. Therefore, in order to gain objective knowledge, it is convenient to take the “” course. An entire section of the course is dedicated to this language.

iOS application development

As a sample we will develop a very simple application. Let us not deviate from the sacred tradition, let us greet the world. However, taking into account the fact that we have a graphical application, we will diversify it a little: we will add a button, when clicked, we will display or hide the inscription “Hello, World”.

Launch Xcode, in the window that appears, select Create new project or in the main menu File -> New -> Project. The next window will ask you to select the target platform and application type.


In this case we are interested iOS platform. There are seven types of applications to choose from. Six of them are blanks typical applications iOS operating system, which by default contain a different set of components. The seventh type is play.

Application Types

  • The Single View Application template is designed for a simple single-screen application. The preset includes a View Controller component, which allows you to customize the appearance of the application using the Interface Builder form designer.
  • Master Detail Application creates an application that displays a collection of objects in a table view. After selecting one of them, detailed information about that object is shown. The first view is the master, the second is the detailing.
  • Page-Based Application creates applications that have multiple screens, like pages in a book. Consequently, e-readers are created from this blank.
  • Tabbed application allows you to create applications where each screen can be switched to at any time, that is, each screen has its own button to activate it, on which the title is displayed. An example is iTunes.
  • Game is used to create a game template. There are four frameworks to choose from for creating a game: SpriteKit, SceneKit, OpenGL ES, Metal. Let's look at them briefly.
    SpriteKit is a system for 2D rendering and animation of textured rectangles - sprites. When displaying frames, a standard loop is used, the frame is displayed after all the contents of the scene have been processed.
    SceneKit is a high-level framework for rendering 3D graphics without OpenGL. It supports loading, manipulating 3D objects. It includes: a physics engine, a particle generator and easy way scripting.
    OpenGL ES is a standard in computer graphics. Allows you to visualize 2D and 3D scenes. Allows you to describe the pipeline for a video card: vertices undergo transformation, are assembled into primitives, which are rasterized into a two-dimensional image and displayed on the screen. Programmable shaders can be included in the pipeline.
    Metal is a low-level API that will allow you to get the most out of your video adapter. Streamlined APIs along with precompiled shaders and multi-threading take your game to new levels of performance and quality.
  • Sticker Pack Application is a new type of application introduced in iOS 10 and Xcode 8. It is a set of simple or animated images used in the new iMessage. It does not require coding to create it.
  • iMessage Application is a new type of application that appeared in iOS 10 and Xcode 8. Allows you to create add-ons for iMessage, for example to purchase and download your sticker pack. You can also use the iMessage API to create your own analogue of this application, including playing audio, video, using stickers, and more.

Creating the first project

As a template for our application, we will select Single View Application. Since we will not be developing a large program, the funds provided by this provision will be enough for us. Click Next. On the next page of the wizard, you need to enter a project name, for example ShowLab. In the Language drop-down list, leave the default language selected - Objective-C. Next, in the Devices drop-down list, leave the Universal selection. Here you determine for which device (iPhone or iPad) the application is being created. The Universal clause means for both. Let's uncheck the Include Unit Tests and Include UI Tests boxes; we don't need any tests. Next. Select a folder to save the project. Now click the Create button.

As a result, a window will open with a list of all parameters applied to the project. In this window, you can change the parameters previously set in the wizard: orientation, target device, etc.


First we need to create the application interface. To do this, select the Main.storyboard file in the list on the left with one click (if this file is not visible, expand the contents of the ShowLab folder). To the right of the list, the entire window will be occupied by Interface Builder. The device layout will be displayed in the center. In the lower right corner of the window there is a component panel. Drag the Label and Button components from there onto the layout. Above the component panel is a list of properties. If you don’t have it, click the Show the Attributes Inspector button, located under the window title on the right side of the interface.

Select the Label component in the layout and configure it Text property: leave the Plain selection in the drop-down list, enter the desired inscription in the line below, in our case “Hello, World”. If the text does not fit within the borders of the label, change them by dragging the handles on the edges of the component. To centralize it horizontally, go to the Size Inspector page by clicking on the Show the Size Inspector button (to the right of Show the Attributes Inspector). On this page, from the Arrange drop-down list, select Center Horizontally in Container.

Now select the Button component, change its Text property to the desired label - Switch. You can center it in the same way as described above.

Creating a connection between graphic elements and code

In Visual Studio (or Delphi), an object in the code is created automatically the moment you place a visual component on the form. This doesn't happen in Xcode, but it doesn't cause problems.

Open the contents of the ViewController.h header file in a separate window by double-clicking on it. This file contains a declaration of an extension of the UIViewController class, marked with the @interface keyword. This feature was added to the second version of Objective-C. Now perform this trick: move the mouse cursor to a component - a text label, hold down the Ctrl key and the left mouse button. Move the cursor to the window with the code (file ViewController.h), a blue line will follow the cursor. Release the mouse and key inside the ViewController interface description.

The Outlet creation window will appear.


This is a property of an object that refers to another object (in this case, a visual component). You need to enter the name of the Outlet object, by which you will access the visual component, let it be lab. Next, the object type is selected, it is selected correctly: UILabel.

Even lower in the Storage list, select the type of object reference: weak or strong. If you choose strong, then the object pointed to by the property will exist as long as the property points to it, in which case it will not be automatically deleted when it is no longer used. On the other hand, when a weak reference is in effect, the object can self-destruct. So, select the weak link type and click the Connect button. As a result, the following line will be added to the code:

@property (weak, nonatomic) IBOutlet UILabel *lab;

Let's make sure that Outlet is a property.

Now let's create an Outlet for the button. The algorithm remains the same. Only for the Name property you need to enter a different name, for example but. The line will be added to the code:

@property (weak, nonatomic) IBOutlet UIButton *but;

As a result, we have two pointers to visual components: lab and but - respectively, an inscription and a button. Now, using pointers, we can manipulate components in code.

Then you need to create a button click event handler. To do this, open the implementation file ViewController.m in a separate window. In exactly the same way as you dragged the line into the header file to create the outlet, from the button, drag the line into the implementation file and drop it to the closing command bracket - @end. A window for creating an event will appear, similar to the window for creating an outlet. You see the difference: a link to an object is created in the header file, a method is created in the implementation file.


Fill in the Name field, its value represents the name of the property - method. Let it be onClick. Leave the Type field value as default - id. In Objective-C this type is the ancestor of everyone else. In the Event drop-down list, the Touch Up Inside event is selected by default, which occurs when the pointer (mouse, finger...) is released over the button, that is, the final stage of pressing the button. That's what we need. In the Arguments list, we will leave the default value: Sender is the object that sent this signal, in our case it will always be a button. Click the Connect button. As a result, the following code will be added:

- (IBAction)onClick:(id)sender ( )

A minus at the beginning means a closed method (private). The IBAction keyword marks events (methods) of visual components from Interface Builder.

Between the command brackets we will write the code that is executed when the button is pressed:

Lab.hidden = !_lab.hidden;

In this line of code we invert the value of the hidden property. It is of type BOOL, which has two values: YES - true and NO - false (somewhat unusual for Windows programmers, where true and false).

Pay attention to the underscore character before the name of the object - the label (_lab). Without it, compilation will fail. The underscore is added automatically for objects contained within other objects; that is, in this case, the lab object is contained in the ViewController object. Previously, this was a convention used to distinguish between objects declared as members of a class and local objects. And now this is a strict rule implemented in the language compiler.

Now you can compile the application and run it on the simulator. We chose the simulator for iPhone 7, included in Xcode 8. The compile and run button is a black rectangle and is located in the bar at the top of the interface.

After compiling the application, launching the simulator and loading our application, its interface will be displayed on the simulator screen: the inscription “Hello, World” and the Switch button. If you press the last one, the inscription will disappear; if you press it again, it will appear again.

We have made a very simple application to understand the essence of iOS development. You can learn more detailed information about creating iOS applications in Objective-C from the course by our friends from GeekBrains “”. The course devotes two months to learning this language. During the first month - introductory topics, and in the second - real coding of professional applications.

Swift language

In 2014, Apple introduced a new programming language - Swift. It quickly became the most talked about and fastest growing language in the world. This is a reliable, secure, intuitive language for developing applications for the macOS, iOS, tvOS and watchOS operating systems for the entire fleet of Apple devices. Swift is an efficient programming language. It's easier to learn than its predecessor, Objective-C, and Swift borrows some of its best ideas. At the same time, the developers have made the languages ​​compatible, that is, one program can contain code in both Swift and Objective-C. There are billions of lines of code and hundreds of thousands of legacy programs written in Objective-C in the world, so its support will definitely not be abandoned.

When developing Swift, the goal was to create the most convenient language System programming is fast, safe and expressive.

The algorithm in Swift is 2.6 times faster than the same algorithm in Objective-C, and 8.4 times faster than in Python. Using Swift makes the program development process more flexible and convenient.

Due to its exponential development, the Swift language was released to the open source community on December 3, 2015. At the same time, Apple strictly monitors its development, organizing a committee for its development. Now Swift is available not only in Apple systems, but also on Linux. All additional tools for working with the language, including a debugger, standard library, package manager, are also free and open.

This language is the future. You can find out more detailed information about it from the mentioned course from GeekBrains “”, in which a whole month is devoted to studying of this language programming.

App Store

Simply put, the App Store is a content store for the entire range of Apple devices. Here you can buy games and applications from both large companies and independent developers. Every developer, no matter what country he lives in, can sell or distribute his programs for free on this digital distribution platform. To start doing this, you need to register as a developer and buy a license to sell your applications. This is a fee for the service provided and the development of the App Store.

Results

We have developed a simple application for the iOS mobile operating system using the Xcode programming system along with the Objective-C language. Tested ready application on the iPhone 7 simulator. We learned how to build a user interface using Interface Builder, how to associate graphic elements with application code, and how to create event handlers. We got acquainted with the basics of Objective-C. In addition, we drew attention to the promising Swift language, used to develop powerful and secure applications for the “apple” ecosystem.

However, the material studied is only the beginning. In order to intensively upgrade yourself in the direction of mobile coding and the development of actually selling applications, we recommend taking the “” course on our friends’ website.

This is a worthy course: if you take it, you definitely won’t waste your time. It starts with two detailed courses on Java language, followed by learning basic programming for a mobile operating system Android system. Further course on databases in general and SQL language in particular. Then an in-depth course on developing professional Android applications. After this, the vector of study will move towards Apple systems: two detailed course in Objective-C language and useful course by Swift.


The course lectures are taught by professional teachers with extensive experience in software development. If something is unclear, you can ask a question without delay. In general, learning on GeekBrains is a live process, you can communicate, ask questions, and help with answers. To test the acquired knowledge, teachers give homework, which is then checked. After completing the training, you will have a guaranteed internship in an IT company. And then everything depends on you, if you show yourself as a competent specialist, you will be invited to work.

Special project with the company

Hello, friends.

I decided to radically change the scope of my activity (optimization and promotion of websites, and online stores) and take iOS development seriously. There is no specific experience in programming at all, everything is only in general concepts at the level of basic theory. I approach the development itself from the point of view of professional development and earning money from it, as well as from the point of view of simply interesting business and possible projects of my own.

I read the toaster on my topic, so questions a la “what books should I read?” I won't ask.

1. How quickly do I need a MacBook to dive into development? I definitely know that in the end I would be nowhere without him. The fact is that buying is not a problem (I’m not a millionaire, but for serious professional changes I’m willing to spend $1000-1500 on working equipment), but is there any point in spending such initial expenses without knowing absolutely nothing about the topic? Is it enough, say, to install on Windows 7 (if so: HP, 2 x 1.7 GHz, 2 GB memory, integrated video) any emulator and at least the first couple of months to understand the initial base and basic concepts?

2. How powerful is a MacBook for an iOS developer? Let's say if it's enough MacBook Air 13" (Intel Core i5, 4 GB, 128 GB (SSD), Intel HD Graphics 5000)? Or look at which MacBook Pro 13"" Retina ( Intel Core i5, 8 GB, 128 GB (SSD), Intel Iris graphics 5100)? Or maybe you need something more powerful (i7 processor, 16 GB memory, video not built-in)? It’s clear that if money allows, it’s better to buy a faster one, but, unfortunately, buying a top-end configuration MacBook is, well, financially inconvenient right now. On the other hand, I don’t really want to take an old MacBook from someone and then change it after six months.

3. Do I need an iOS device to start learning development? Or will it be possible to somehow emulate an iPhone on Windows 7 / OS X to see what happens? Or is this done in some other way? :-) Again, buying is not a big problem, but do I need it now? And, if necessary, another related question: should I buy something fresh (5 / 5s) or not important (4s)?

4. Is there a need for classic Objective-C courses? Or is it better to figure it out yourself from scratch? I live in Minsk, the courses are nothing special, everything is ordinary (approaches, techniques, general level). I also know that programming is constant self-learning. Question: does it make sense to take a month-long course to get a starting base, and then move on on your own? Or can you start at home without any problems?

5. How to plan the self-study process? Nothing new: I read it - I tried it, it’s not clear - I looked it up on the Internet, it’s very unclear - let’s go to the forum? It's just been about that long since I learned HTML. But, of course, Objective-C is a serious matter, like all related technologies, and will such training be of any use? Or do you need some specific system and a clear gradation for increasing your level (first read a book, then take a course, then study this related technology, and so on)? Please tell me how you were involved in iOS development.

Future colleagues, I am sure that during the learning process I will have a lot of questions for which it is a shame to create new topics. If any of you have the opportunity to answer my questions a couple of times a week and provide brief advice on any topic, please let me know about it in your replies (leave your any contact details and conditions (free/paid, etc.)). Everyone has their own business, there are very few altruists - I understand everything, so my appeals to you will be as rare as possible and to the point.

Thank you very much for your attention and interest in my questions. Have a nice week everyone! ;-)







2024 gtavrl.ru.