iOS Fundamentals 01 build HelloWorld, anatomy and real-machine testing

Source: Internet
Author: User
Tags dashed line

iOS Fundamentals 01 build HelloWorld, anatomy and real-machine testing

Objective:

Output from the console HelloWorld is our first step in learning various languages and is a very important step in our life.

After many years, I hope that we can still have the mood to learn, continue to HelloWorld to know more things in the world.

This article takes HelloWorld as a starting point to introduce you to what iOS apps are and how to use Xcode to create iOS apps.

Directory:

1. Create a HelloWorld project

1.1. Design interface

1.2. Real-Machine testing

2. iOS project templates in Xcode

2.1. Application Type

2.2. Framework&library Type

2.3. Other types

3. Application Anatomy

4. Finally, let's pull a duzi.

1. Create a HelloWorld project

Start Xcode, then click on the File-new-project menu, or click "Create a New Xcode project":

In the open choose a template for your new project interface, select the single View Application project template:

Then click on the Next button and then prompt to enter information such as project name:

Here we can follow and combine their own actual situation and need to enter the relevant content.

Here's a brief look at each of the options:

Options Description
Project Name The name of the project.
Organization Name The name of the company or organization.
Organization Identifier

Identification of the company or organization (very important).

In general, the domain name of the company or organization is entered here (such as COM.GEEKSSS). The wording is similar to the package name in Java.

Bundle Identifier

Bundle identifier (very important). The identifier is composed of Project Name+organization identifier.

Because it is used when the app is published on the App Store, its name is not duplicated.

Language

Develop language selection.

You can choose the language you use to develop your application, and you can choose Swift and objective-c in Xcode 6.

Devices

Select the device. You can build an iphone or ipad-based project, or you can build a generic project.

General engineering refers to a project that works on both the iphone and the ipad.

After setting the relevant project options, click the Next button and follow the prompts to choose the location of the project file:

Once you have selected the storage path, click the Create button and the project is finished.
You can open the corresponding designer in the edit area by selecting Main.storyboard in the project resources list:

In the lower-right corner of the object library, select label, drag it to the view design interface, and adjust its position.

Double-click the label so that it is in the edit state (or set by the property of the control), where you enter HelloWorld:

After you add a Label control, you need to set the label control's position.

Drag the Label control and a blue dashed line appears, indicating that the label is now in the horizontal center position:

However, if you run the instance now, we will find that the label is not centered and you need to add the auto layout constraint to the label.

About auto layout constraints related content, and so on after the special son introduced it.

We select the Resolve auto layout issues (solve auto layout problem) button in the toolbar and select Add Missing constrains (add missing constraint) in the popup menu:

When added, two blue vertical lines appear above and below the Label control:

At this point, the entire project has been created.

, select the emulator or device you are running, and then click the Run button in the upper left corner to see the results of the operation:

After clicking Run, if it is a real machine test, you will be prompted for your Apple ID account for the first time to enter. When you're done, you'll see your app on your phone's desktop:

But when we open it, it prompts the app to come from an untrusted developer, with restricted opening.

After all, I did not purchase a developer certificate. Oh:

Here we follow the prompts to find the settings:

General:

Device Management:

In the developer list, select the account you just entered in Xcode:

Then you'll see a list of all apps for that account, and click Trust the Developer:

Then there will be a hint to be sure to trust this guy? OK:

We will then see that our application has been validated:

Back to the desktop, click on the Launch app, OK, an exciting interface is greeted:

Although the interface is very high arsenic, not tall bar. But without entering any code, we've created a project and run it successfully using the Xcode tool's single View application template.

The power of Xcode is evident.

2. iOS project templates in Xcode

Just as we created the project, we can see that the iOS project template is roughly divided into 3 categories: application, Framework&library, and other.

The three types of templates are described below:

2.1. Application Type

Most of our development work starts with creating iOS programs using the application type template. This type contains a total of 5 templates, as follows:

Template Name Template Introduction
Master-detail Application You can build a tree-structured navigation mode application, and the generated code contains navigation controllers and table view controllers.
Game You can build an iOS-based game app.
page-based Application You can build an app that resembles an ebook effect, which is a tiled navigation.
Single View Application You can build simple, single-view apps.
tabved Application You can build the app for the label Navigation mode, and the generated code contains the tag Controller and tab bar.

2.2. Framework&library Type

Famework&library type of template that can build applications based on the cocoa Touch framework and the Cocoa Touch Static library:

The Cocoa Touch Framework allows developers to customize the framework applied to Uikit, while the Cocoa Touch Static library allows developers to create static libraries based on framework frameworks.

Because of code security and the consideration of multiple engineering reuse code, we can write some classes or functions into static libraries.

The static library cannot run independently, and a file named Libxxx.a (for example, LIBHELLOWORLD.A) is generated when the compilation succeeds.

2.3. Other types

With this type, we can build in-app purchases (In-app Purchase content) and empty projects.

, using in-app purchase content packs can help us build apps with built-in billing features:

We can use different engineering templates as needed, which can greatly reduce the workload.

3. Application Anatomy

During the creation of the HelloWorld, a lot of files were generated (as you can see in the project Navigation view on the left of Xcode),

There are four groups of HelloWorld, Helloworldtests, helloworlduitests and products under the Navigation view.

Where the HelloWorld group is placed in the HelloWorld project engineering important code, and Helloworldtests group is placed in the HelloWorld program's unit test code, The Helloworlduitest group is placed in the test code that automatically tests the UI and interacts with the compiled project files placed in the products group.

Next, let's focus on the project content in the HelloWorld group.

In the HelloWorld group, there are two classes Appdelegate and Viewcontroller, two interface layout files Main.storyboard and Launchscreen.xib, and one group supporting files.

The Main.storyboard file is a storyboard file (highlighted in the next section), and Launchscreen.xib is the Xib file that applies the launch interface. The storyboard file is similar to the Xib file.

Our main coding work is in the two classes of Appdelegate and Viewcontroller, their class diagrams:

Appdelegate is the application delegate object, it inherits the Uiresponder class, and implements the Uiapplicationdelegate delegate protocol.

The Uiresponder class enables subclasses appdelegate to have the ability to handle the corresponding event, whereas the Uiapplicationdelegate delegate protocol enables Appdelegate to be an application delegate object that responds to the application's life cycle.

Accordingly, the subclass of Appdelegate can also implement these two functions.

The Viewcontroller class inherits from the Uiviewcontroller class, which is the Controller class for the view, which plays the role of the root view and the user event controller class in the project.

The Appdelegate class is an application delegate object, and a series of methods inherited in this class are called back at different stages of the application life cycle, and are defined as follows:

When you start HelloWorld, the Application:didfinishlaunchingwithoptions method of circular circle is called first, and the other methods are described in detail later.

In the project Navigation view, we can see that there are also images.xcassets files, which can be placed in the project's picture.

The supporting files group has only one info.plist file, which is a project property description file that holds the property settings for the project.

Products Group is the product package for the project to produce the car function.

Description

When you access a resource file, the folders and groups are different, and the resources in the folder are accessed with the folder as the path.

If the Icon.png file is placed under the image folder, the path to access it is "image/icon.png", and if the image is a group, the path to it is "icon.png".

4. Finally, let's pull a duzi.

No end always feel not good-looking ...

If this article is helpful to you, do not forget to poke at the bottom right corner of the thumb Oh, hehe.

  

iOS Fundamentals 01 build HelloWorld, anatomy and real-machine testing

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.