Swift starts learning _05 from scratch

Source: Internet
Author: User
Tags shallow copy

From two to see now, almost two hours, are some of the conceptual things, mostly by understanding and memory, which involves the value of swift Reference and type reference, deep copy and shallow copy, etc., personally think these things are by understanding, the code is not clear, So the code is not written so much in the afternoon. Here are just a few lines of code to write.

// Enumeration // enum viewframe{// enumeration needs to start with a capital letter //case    x//case    Y//case    width//case    height//} 
// multiple members can also be separated by commas enum viewframe{    case  x, y, width, height}
var a = Viewframe.width//the values in the enumeration can be obtained through the. Syntax.A =. Height//When the type of a value is known, and then set his value, the type name is not required.Switcha{ Case. X:PRINTLN ("x Value") Case. Y:PRINTLN ("y value") Case. WIDTH:PRINTLN ("Width Value") Case. HEIGHT:PRINTLN ("Height Value")default: println ("other")}
enum Planet:int {    case1, Venus, Earth, Mars, Jupiter, Saturn, Uranus, Neptune}/ / int Here is the original value of the enumeration value, which is incremented when the original value is defined as int. // the RawValue property can access the original value, RawValue: The enumeration member can be found by the original value let x =2)
//classclassperson{//Create a person classvar name:string?var sex:string?var age=0}var Person1= Person ()//Creating ObjectsPerson1.name ="Chris"//assigning values to object propertiesprintln (person1.name)//A class is a reference type, and unlike a value type, a reference type is assigned to a variable, a constant, or is passed to a function, and the operation is not a copy of it. Therefore, the reference is made to the existing instance itself, not to its copy. For example, assigning an object to a and assigning A to B will change a or b at this time, essentially changing the same instance variable, which is called the reference type. (somewhat similar to the light copy in OC)//A struct is a value pass that can be understood as a deep copy object in OC//identity symbol, = = = equivalent to,!== is not equivalent to detecting two constants or whether a variable refers to the same instance variable

Swift starts learning _05 from scratch

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.