9.2. Swift environment building

发布时间 : 2025-10-25 13:33:51 UTC      

Page Views: 9 views

Swift is an open source programming language for developing OS X and iOS applications.

Before the formal development of applications, we need to build a Swift development environment, in order to better use a variety of development tools and languages for rapid application development. Because the Swift development environment needs to run in the OS X system, so the constructionof its environment will be different from the Windows environment. Let’s learn how to build the swift development environment.

The prerequisites for successfully building a swift development environment:

  1. You must have an Apple computer. Because the integrated development environment XCode can only run on OS X systems.

  2. The computer system must be OS 10.9.3 or above.

  3. The computer must have the Xcode integrated development environment installed.

9.2.1. Download Swift development tools Xcode #

The official website address of Swift development tools is https://developer.apple.com/xcode/download/ .

Swift source code download: https://swift.org/download/#latest-development-snapshots

After the download is complete, double-click the downloaded dmg file to install, and after the installation is complete, we will move the Xcode iconto the application folder.

Image0

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

9.2.2. The first Swift program #

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

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

Image1

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

Image2

Swift’s playground is like an interactive document, it is used to practice hand-learning swift, write a sentence of code to produce a line of results (right), you can view the code results in real time, is a sharp tool to learn the swift language!

Image3

The following is the default code for the Swift Playground window:

import UIKit var str = "Hello, playground" 

If you want to create an OS x program, you need to import the Cocoa package``import Cocoa`` the code is as follows:

import Cocoa var str = "Hello, playground" 

After the above program is loaded, the program execution result will be displayed on the right side of the Playground window:

Hello, playground 

So far, you have completed the study of the first Swift program. Congratulations on getting started.

9.2.3. Create the first project #

1.Open the xcode tool and select File = > New = > Project

Image4

2.Let’s select a “Single View Application” and click “next” to create asimple example app application.

Image5

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

Language has two options: Objective-c and swift, because we are learning swift, of course, choose the swift item. Click “Next” next.

Image6

4.Select the directory to store. If you want to use Git source control, youwill check Source Control’s create git repository on My Mac. Click create to create the project.

Image7

5.After the project is created, a sample file is generated by default. You can see that swift merges the h and m files in oc into a file (that is, the swift suffix file). Main.storyboard is the equivalent of a xib file and has more functions than xib.

Image8

6.Open main.storyboard can see a simple, blank application interface by default, the size of which is the size of a flat interface. If developers only need to develop app that is compatible with iphone phones, you can uncheck Use Auto Layout (the default is checked).

Image9

7.A dialog box pops up, let’s choose the interface size, iPhone or iPad. We choose the size of the iPhone.

Image10

8.You can see that the interface size has changed to the width and height of the phone’s iphone.

You can remember the dimensions related to the interface to facilitate the layout and calculation location in the future:

Image11

9.We add something to the interface, find the Text control at the bottom right, drag it onto the storyboard, and double-click to write the text “Hello World!”.

Image12

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

At this point, our first Swift project is complete.

《地理信息系统原理、技术与方法》  97

最近几年来,地理信息系统无论是在理论上还是应用上都处在一个飞速发展的阶段。 GIS被应用于多个领域的建模和决策支持,如城市管理、区划、环境整治等等,地理信息成为信息时代重要的组成部分之一; “数字地球”概念的提出,更进一步推动了作为其技术支撑的GIS的发展。 与此同时,一些学者致力于相关的理论研究,如空间感知、空间数据误差、空间关系的形式化等等。 这恰好说明了地理信息系统作为应用技术和学科的两个方面,并且这两个方面构成了相互促进的发展过程。