Latest web development tutorials

Swift environmental structures

Swift is an open source programming language, the language used to develop OS X and iOS applications.

Before the formal development of applications, we need to build Swift development environment to better use friendly language and development tools for rapid application development. Because Swift development environment needs to run in OS X system, so the built environment will be different from the Windows environment, following up on a study about the procedure of setting up swift development environment.

Successfully built premise swift development environment:

  1. You must have an Apple computer. Because the integrated development environment XCode can only run on OS X systems.
  2. Computer systems must be in OS 10.9.3 and above.
  3. Your computer must install Xcode integrated development environment.

Swift Xcode development tools download

? Swift Development Tools official website address: .

Swift development tools Baidu Software Download Center (Domestic faster):

Swift Source Codes:

After the download is complete, double-click the downloaded dmg file is installed, the installation is complete we will Xcode icon to your Applications folder kick move.

You can also search xcode installed in the App Store, as shown in the following figure:

The first Swift program

Xcode after the installation is complete, we can start writing Swift code.

Next we open the folder in the application file Xcode, open at the top of the screen, select File => New => Playground.

Then set a name for the playground and select the iOS platform.

Swift's playground is like an interactive document, which is used to practicing hand learn swift, and write a line of code is the result (on the right), you can view real-time results of the code, it is to learn the language swift weapon!

The following is the default code window Swift Playground:

import UIKit

var str = "Hello, playground"

If you want to create OS x, we need to import packageimport Cocoa Cocoa code as follows:

import Cocoa

var str = "Hello, playground"

After the above program is loaded, it will display the results of the program in the right window Playground:

Hello, playground

At this point, you've completed the first program of study Swift Congratulations beginning.

Creating your first project

1, open the xcode tool, select File => New => Project

2, we have chosen a "Single View Application", and click "next", to create a simple example app application.

3, then we enter a project name (ProductName), Name (Organization Name), company logo prefix (Organization identifier) ​​also select development language (Language), select the device (Devices).

Language in which there are two options: Objective-c and swift, because we are learning swift swift course, choose the item. Click on "Next" the next step.

4, select the storage directory, if you want to use the Git source code management, the hook on the Source Control create git repository on My Mac. Click to create create the project.

5, after the project is created, the default generate a sample file, see the swift will oc h and m files merged into one file (ie swift file extension). Main.storyboard equivalent xib file, there are more than xib multi-function.

6, open main.storyboard, default see a simple blank application interface, the size of flat screen size. If developers only need to develop a compatible iphone phone app, you can Use Auto Layout check out (the default is on the hook).

7, a dialog box pops up, let us choose the size of the interface, iPhone, or both iPad. We choose the size of the iPhone.

8, you can see, the size of the interface into the phone iphone width and height.

We can remember in this screen size, calculating a position to facilitate future layout:

iPhone or iTouch a width of 320 pixels and a height of 480 pixels, the status bar is 20 pixels high, toobar height of 44 pixels, tabbar height of 49 pixels, the navigation bar is 44 pixels high.

9. We add content to interface points, found in the bottom right of the Text control, it will be dragged into the storyboard, and double-click to write the text "Hello World!".

Run the simulator (command + R shortcut or select Product => Run in the menu bar).

At this point, our first Swift project is complete.