S-- The Swift learning content is based on the content of the following URL
Https://developer.apple.com/library/ios/referencelibrary/GettingStarted/DevelopiOSAppsSwift/index.html#//apple _ref/doc/uid/tp40015214
In this course, you will step into the language of swift and eventually learn to develop a simple iOS App with Swift.
Before you begin, you need to prepare some basic tools:
1. You need a device that is running OS X 10.10 or a higher version of the system
2. Install the latest version of Xcode on your device via the App Store
If you are ready, let's get started!
W--- has a good helper in learning Swift with Xcode, which is playground. In playground, when you have entered the code, you can see the results immediately, which is helpful for beginners to understand the function of the code. such as:
You can see get started with a playground when you open the home page of Xcode, and you'll be able to create your own playground with this feature. Of course you do not need to do this, because in this course has long been built for you playground, that is, the equivalent of the curriculum in the playground, the code used in the course can be like, directly to the results displayed, it is really convenient! Download the tutorial from the URL below!
Https://developer.apple.com/sample-code/swift/downloads/Start-Dev-iOS-Apps-01.zip
After downloading, unzip and then use Xcode to open the Learn the Essentials of Swift.playground file in the Start-dev-ios-apps-01 folder, and if you see just the picture below, don't be nervous,
You can get the entire playground screen by clicking on the three boxes in the top right corner of the screen.
I -----Preparations are in place, let's take a look at the learning goals of this lesson, what we can learn after we finish this class .
- The difference between a constant and a variable
- Know when to use an implicit declaration when using explicit declarations
- Understand the benefits of using optional types and optional bindings
- Distinguish between optional types and implicit parsing optional)
- Understanding the purpose of conditional statements and circular statements
- Using a switch statement to handle conditional branches over $ two
- Use the WHERE statement to attach additional restrictions to conditional statements
- Distinguishing functions, methods, and construction methods
- Distinguishing classes, structs, and enumerations
- Understanding inheritance and Protocol consistency
- Determine when to use implicit typing and use the quick Help features of Xcode to find more information
- Learn to import and use Uikit
F---- with the above learning objectives, let's start with the specific learning content, in this lesson we'll just learn a little bit about swift and see how it differs from other languages.
a--Take a look at the following code:
var myVariable = 42
myVariable = 50
let myConstant = 42
define variables in Swift with the var+ variable name, such as the 1th line of the above code; Define constants with let+ constant names, such as the 3rd line of the above code;
Defining a variable in Swift is not the type of the variable, but rather the system infers the type of the variable by assigning a value to the variable when it is defined, such as in the above code that the system infers that the variable myvariable is an integer variable, because the value 42 assigned to myvariable begins with the integer type. This inference is called type inference (inference).
b-- and look at the following code:
-
let Span class= "VC" >implicitinteger = 70
-
let implicitdouble = 70.0
-
let explicitdouble: double = 70
If the system is not sufficient to infer the constant or variable from the value assigned to the constant or variable, or if it is simply not assigned, in order to determine the type of the constant or variable, a colon should be appended to the constant or variable name and the type will be written after the colon. As in line 3rd of the above code.
T---- The first lesson on so much content, language learning is more boring process, but lofty high-rise flat, only a little bit of continuous learning, can continue to deepen the understanding of the language. In addition, in the process of learning to think more, diligent hands can do more.
01-meet Swift!