A lot of new people are confused about IOS development and don’t know where to start. By the end of this series, getting started on IOS is pretty easy.
To learn IOS development, of course, is to learn Swift language first, especially xiaobai, you do not even understand the basic code, further
Learning is very passive.
First, development environment configuration
1. To develop IOS, you must first have a MAC. If you use Windows, go home.
2. The development of Apple application software must use Xcode software, including our IOS development (mobile application software). Xcode installation is very simple, use the “App Store” download and install, don’t know your own query. The current Xcode version is 9.4, the corresponding Swift version is 4.1, and the IOS SDK is 11.4. Xcode comes with Swift and ISO SDK and does not need to be installed and configured separately.
Do IOS development can use Object C and Swift two languages, the preferred language of course is Swift language, which is the trend and easy to use.
2. Create a project
This chapter is only for people to learn Swift language faster and better, so we only need to build the simplest Playground project, whose advantage is that we can quickly compile and check the results.
1. First open the Xcode app and then click the red box in the picture
2. Make sure “iOS” and “Blank” are selected in the upper left corner, then click “Next” in the lower right corner to go to the Next screen.
3. After “Save As:”, enter the name of the project. You can select a place to Save the project.
The following page is displayed:
Some people say, why do I not have the left and right or the following blocks, you can click the buttons in the upper right corner to pull out:
A brief introduction to the functions of each panel block:
1. The left block shows the directory structure of the project;
2. The upper middle block is our “code area”, where we enter the Swift code;
3. The lower part in the middle is the result “output area”, we mainly use the middle two pieces below;
4. The right part has not been used for the time being, so there is no explanation.
In the development interface, the blue button at the bottom left in the middle is the compile button. After writing the code, click this button directly to compile:
Xcode can only set the color of the code area. Xcode can only set the color of the code area.
Write code
In fact, after creating the project, there are two lines of code in the middle “code area” :
The first line import is a keyword that is used to import systems or third-party libraries, libraries that have all kinds of functions and all kinds of functions, like UIKit that can help us with views.
The second line defines a string variable, more on that later.
The following code is written in the “code area”. It is best to type each line by hand. It is an effective way to become familiar with a programming language.
1. Output to “Result area”
For visual purposes, we first use a line of code to output the result in the “result area”, and type the following code in the third line of the “code area”
print(str)
Copy the code
Then click the “compile” button in the blue triangle. You can see the output area, which prints out a line of words. All the rest of the time, you can print it out to the output area in this way.
Constants and variables
Swift uses the var keyword to define variables and let to define constants
var a=5
let b=6
print(a+b)
Copy the code
The output area is 11
3. Data types
Let c:Int=70// Int var d:Float=70// single precision Float let e:Double=70// Double precision Float var tt="this is pen"// String typeCopy the code
4. The string
let myString="result is "
let myInt:Int=94
let myString1=myString+String(myInt)
let myString2="result is \(myInt)"
print(myString1)
print(myString2)
Copy the code
MyString1 and myString2 output result is 94
MyString1 uses String(myInt) to convert Int data to a String, while myString2 uses \() to convert numeric data to a String
5. Array types
var array=["one","two","three","four"]
var getTwo=array[1];
print(getTwo)
Copy the code
The input result is two
6. Data dictionary
var dictionary=["oneName":"I am one value","twoName":"I am two value"]
var getTwoValue=dictionary["twoName"]
print(getTwoValue)
Copy the code
The output is: Optional(“I am two value”)
7. The enumeration
Enum Week{Case Monday Case Tuesday Case Wednesday Case Thursday Case Friday Case Saturday Case Sunday} var Week :Week Week =Week. Print on Monday (week)Copy the code
Output: Monday
There’s a lot more to learn about Swift, but this is just a quick primer. Two suggestions for Swift:
1. It is recommended that when you start learning Swift, you should type all the codes with your own hands.
2. After learning some common knowledge of Swift, it is necessary to apply it in practice. There will definitely be problems with Swift in practice, and then go back to learn Swift related content.
More information about Swift language can be seen in the following links, and it is suggested to collect, and you can also inquire when you encounter problems in the future:
www.cnswift.org/the-basics
This series will continue to be updated, but if you are interested, you can click on the next section:
Introduction to IOS Development # 2 – First App
The article will continue to be updated, you can also send me a message to get the latest information and interview information. If you have any comments and suggestions, please leave a message to me.