Start with the Pitre "Swift Basic Tutorial 2nd"

Source: Internet
Author: User

Read the two days "learn objective-c on the MAC" Chinese version of "Objective-c BASIC programming", probably read the 9th chapter of the Memory Management Section, feel that the language is much simpler than C + +.

On the first day, because of the C Language Foundation, I installed the GNUstep (OBJECTIVE-C) development environment on Windows, changed to read the electronic books, side on the PC to compile the example on the tree, almost one did not miss, but also made a lot of notes. (after all, the author Mark dalrymaple & Scott Knaster is strategically advantageous position, the narrative technology, will actually very deep technical points in layman's words, concise, also will OBJC and C language contrast to illustrate, impressive). Unconsciously on the first day after reading the top 8 chapters.

But from the 9th chapter of the Memory Management Section, it is not so good to chew.

“...... We often complicate these rules, and it is also a common mistake to ignore these rules. If you are aimlessly abusing retain and release Method 1?? Fixing these errors means that you haven't really mastered them yet. You need to slow down, take a break, and then read on ... " In "Objective-c BASIC Programming", the author says.

See how good, haste and waste.

At the same time, I also look at the posts before I go to sleep, to check the predecessors ' learning suggestions and curves.

The personal summary is as follows:

    1. If you are sure that you want to develop under Mac/ios,Objective-c & Swift must learn , and people with OBJC Foundation should never underestimate the learning of swift, and of course learn C + + Objc/swift Disdain of the morning and evening have regretted the day. After all, language is just a tool, if you are familiar with a language, the cost of learning Objc/swift will be very small.
    2. Individuals in the first two days determined to start the Mac book before the survey on the app Store, summed up the conclusion is: technology in the Mac/ios is not a bottleneck, rare is the idea and creativity. So before you decide to develop a project, do some research, profitable to continue to do, do not immerse yourself in technical research and endless coding , so it is not interesting.

See "Objective-c BASIC Programming" preliminary to OBJC have a preliminary understanding, (more than C + +, but more than C, but more than a lot of control, in fact there is a lot of difficulty).

But Swift is an easy-to-use language, borrowed in the library of Pitre's "Swift Basic Tutorial 2nd", a cursory turn, the language can be very similar to javascipt.

Okay, get on the road.

    • The Swift 2 is Apple's modern language from scratch, powerful and easy to learn. Apple has used it as the development language for the growing Ios/watchos/tvos/mac OS X application
    • Xcode Current latest Xcode version is Xcode8.3
    • LLVM in Xcode, LLVM works behind the scenes, and this compiler technology makes swift language elegant and translates swift code into machines that Apple device processors can run
    • REPL (read-eval-print-loop) is a command-line tool that you can use to quickly try swift code. In Mac OS x, you can run it in terminal
    • Playground provides interactivity and real-time results in Xcode, ideal for learning Swift

While reading and practicing while writing essays:

Chapter 1 Swift Introduction

1. Enter Xcrun Swift in terminal to enter REPL for swift code testing

2. Use var to define variables, use let to define constants

3. Swift Basic Type:

Bool, Int, Int32,int64,int8,int16, uint,uint32,uint64,uint8,uint16,float,double,character,string

4. Mathematical arithmetic plus (+), minus (-), multiply (*), except (/), all languages are a virtue at this point.

5. Numerical notation, binary, octal, 16 binary, scientific notation, with C

6. Easy display of strings

Use embedded notation \ () to refer to variables/constants, such as

Let  n=10let  name= "Tom"  to City= "Shanghai" Print ("I am \ (name), from \ (city), age=\ (n)")

7. Use Typealias to define aliases, as in the TypeDef in C, as

Typealias Eightbits=uint8var reg:eightbits=0

8. Ganso (Tuple) Ganso is a single entity consisting of one or more variables/constants/literals, such as

Let mydreamcar=, "Mercedes-benz", "M-class") print (mydreamcar.0) print (Mydreamcar.1) print (MYDREAMCAR.2)

9. Optional type, (now you don't know what this is?) )

var v:int?

Chapter2 Collection

1. Arrays

Let candyjar=["peppermints", "Gooey Bears", "Happy ranchers"]print (Candyjar[0]) candyjar.append ("Candy canes")//!!! Error, the array is Constantvar Refillablecandyjar =candyjar//assigns a constant array to the variable array refillablecandyjar.append ("Candy canes") Refillablecandyjar+=[peanut clusgters "];refillablecandyjar+=[" Banna Taffy "," Bubble Gum "]var h20:[string]=[" Hydogen "," hydrogen "," Oxygen "]; If you want to specify the type of its value when declaring an array

As with C, the array must contain the same element type.

A mutable array is defined with Var, and a constant array is defined using let.

The array in swift language can be likened to vector vectors in C.

The array in Swift can be modified/replaced (Specify the array index and assign it a new value), delete (Removeatindex/removelast), insert (insert:atindex), merge (+)

    • Dictionary

The dictionary consists of two different parts: the key (key) and the value, the type of the key and the value can be different, but all the key types must be the same, and all values must have the same type.

VA r dict =["one": 1, "one": 2, "three": 3, "four": 4]print (dict["one"])  //finddict["Five"]=5//adddict["one"]=11// updatedict["One"]=nil//deletedict.removevalueforkey ("one")//delete
    • Array of arrays

Todo

Add some codes

    • Creating empty arrays and dictionaries
var myemptyarray:array<int>=[]//orvar myemptyarray=[int] () myemptyarray+=[33,44,66]myemptyarray=[]  // Delete all Itemsvar myemptydictionary =dictionary<string,double> () myemptydictionary =["MyKey", 12.34]
    • Array iterations
Method 1for ItemName in list {... do something with Itemname}//method 2//the value of the array of iterations and its index for (index, candy) in Combinedrefilla Blecandyjar.enumerate () {  print ("Candy \ (Candy) is in position \ (index) of the array")}

    • Iterative dictionaries
For (index, value) in Arceneauxsothercandyroute {print ("\ (key) have a candy jar with the following contents:\ (value)")}

Swift Basic Data Type Learning & introduction completed

<chapter 2 End >

Start with the Pitre "Swift Basic Tutorial 2nd"

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.