Lesson 1 - Creating and managing a project in iOS
This lesson shows you how to create a new iOS project with Xcode.
|Expected duration||30 minutes|
|Topic||Creating an iOS project|
|Objective||Create an iOS Studio project and learn about iOS dependencies.|
- To understand better the files of the new project go to: https://youtu.be/ErZFCOv2y2A
- Constraints/AutoLayout in Xcode: https://www.youtube.com/watch?v=7iT9fueKCJM
- iOS Good Practices: https://github.com/futurice/ios-good-practices
Creating a new project
The first thing to do is to create the project in Xcode. Execute Xcode and you will see a initial window like the following:
Click on the option “Create a new Xcode project”. This allow you to create applications for iOS, tvOS, macOS, watchOS devices, among others.
After clicking that option, a window will appear, in which you have to choose the type of the application. You can create games using SpriteKit18, you can create applications from templates and also sticker o iMessage applications, and there are more other options. For this case choose “Single View Application”, that is the most basic of all and it only comes with a controller an a simple view.
When you click on next, you will need to select the basic information of the project, that is: the name of the application, the development team, the name of the organization, the id of the organization (commonly the inverted domain), the programming language that will be use in the project, and finally, if the project will have tests.
After filling the basic information of the projects, this will be store in your machine. Choose the location and click continue.
Xcode will create the project and open the editor. This first view shown by Xcode corresponds to the general information of the project, including the one set in the previous steps. In this lesson we will not make modifications, but we will show the modifications that you could do.
You will see that in iOS the projects have “Targets”. This corresponds to the applications, the extensions and tests that exists inside the same environment. For example, a target could be our application and other could be an extension for the apple watch. Although both share basic information and share the same ecosystem, they run in different devices and environments. The first thing to do is to make sure that the target selected is the one with the name of the application.
Once there, the first section corresponds to the basic information of the application. You will also find the version number of the app, this number is really important for the moment when the app is going to be upload to the App Store. There is another number, that refers to the Build, this number identifies, inside the same version, in which build the app is.
Another section is the “Signing", in this section you will configure everything related to the signing of the app, so it can be publish in the App Store using your credentials. In Xcode 8+, this signing of certificates is automatically generated by the IDE. You just need to add the development account and then select the development team associated. In this case, and because the app is not going to be publish, you can select the option of not having a developer account.
After that, you will find the deployment section of the app. Here you can change the iOS minimum version need to execute the app. You can also modify the supported devices, in case you want to add or remove some. You can also configure the file that contains the main interface of the app (check literl B), configure the orientation supported (when you turn the devices) and also configure the color and the initial behavior of the status bar (where the battery is located).
Descriptions of the functionalities of the IDE Xcode
Xcode have the objective of facilitating the development of apps in iOS. Is because of this that the interface of the IDE is not overwhelm with functionalities. The important stuff is find in the edges of the window. In the top is the state bar in which you can execute the actual Target in the selected device and likewise you can stop the execution at any time.
There is a state bar that shows the actual state of the target executed. In this bar you can see messages about the compilation process, indexation problems and even IDE downloads.
Finally, in the top part there is also six buttons which functions is to modify the visual aspect of de IDE. The buttons to the right show and hide sidebars and the bottom bar of Xcode. While the buttons to the left modify the middle window. The first button shows the files in a way that they occupied 80% of the content view, while the second button allows you to divided the central view in two parts to be able to edit two files at the same time.
In the left bar of Xcode, you will find the project browser. There you can see all the files that exist in the project. iOS projects are normally arrange like this:
The main file is the blue one in the left bar, that is the project itself, and inside the project there are folders for each of the targets. There is one folder for for the products that the app generates and one for the libraries (named Frameworks in iOS). This way of arranging the project is not crucial for the behavior of the app, but it is necessary to maintain an order when a project starts to grow.
However, in this left bar you will not always find the project browser. With the top left buttons bar you can change the content of the left bar.
The second tab is the one that shows the source control. We highly recommend to do the management of your git repository from here and not from git terminal or a git GUI client. The source control is the ideal place to manage your git repository, because an Xcode project has a lot of local files that should not be upload to your repository.
The third tab corresponds to a view of the project, not of files, but of classes and its methods. If you click on a method in this view, it will take you directly to the line of the file where the method starts.
The fourth tab will show you the find navigator, with this tool you can search for keywords, code, name of variable, etc. This finder will show you the file that have the things that you are looking for.
The next tab is the view for warnings and errors of the project. It is really useful to see all the problems in one view.
The last four windows will be explained in later lessons.
Libraries? You have use libraries before, and you know the advantages and problems of using them. In iOS the dependency manager is called CocoaPods. Watch the following video to learn more about CocoaPods.
The video is fun, but a little bit old, so when you finish with the installation of CocoaPods (https://cocoapods.org/) open the terminal and go to your application project folder, once there, execute the command \‘pod.init\’. If any error occurs, check the installation of CocoaPods or check if your are in the right folder. When you execute the command a file called \‘podfile\’ should have been created. In this file is where you will add the libraries that you want to use in your project.
There are many libraries that could help you in your project. Here is a list of some important ones:
|RestEssentials||Is a lightweight REST and JSON library for Swift|
|MBProgressHUD||Is a really useful library to make loading dialogs.|
|Reachability.swift||Lets you know the connectivity state of your phone, you can the internet network status, the wifi status, etc...|
|Cosmos||A star rating control for iOS|
This was a first introduction of the IDE Xcode, its functionalities and how to create a iOS project. It is important to clarified that the complexity of the lessons will increase in the moment that we add sensors and other functionalities, but the general structure of the project will remain the same. The image content and the brand names used in this lab belongs to Apple, Inc.
Version Author Date 1.0 Juan David Cruz August 20, 2017 2.0 Juan Santiago Acevedo and Sergio Yodeb Velasquez Yepes February 2, 2018 2.1 Sergio Yodeb Velasquez Yepes February 28, 2018 2.2 Laura Natalia Bello Jimenez January 26, 2019
For academic use exclusively.