Swift Contrast Learning (i)

Source: Internet
Author: User

Swift is more than Objective-c, and with objective-c seamless integration, is a sharp weapon. In Swift, you can see the different programming language of the Shadow, the world language a big copy, so good, reduce the learning cost of different languages.

Let and Var, compared to only the language of the Var has a choice, if the value of the variable will not be modified, let it, the intention is more explicit.

var sidelength:double, Pascal also declares the variable type, typescript also do this, or better acceptable.

The end of the line does not have to add a semicolon (of course you have to add also good), a return to the normal C language family, perhaps learn more Pascal?

Getter,setter everyone has been accustomed to, C#,java have, but Willset,didset is very innovative.

Enum Rank:int {case  aces = 1 case Tow, three, four case Jack, Queen, King}

Enumerating members in case declarations is still interesting.

Protocol equivalent to C # interface;extension is basically equivalent to C # extension methods, but more powerful, you can extend existing classes to implement specific protocol.

Generics, C # already have, Java also qiantouming, say their ancestors is not C + + template Ah?

Println the perfect alternative to NSLog, string interpolation (strings interpolation) is also very strong, C#6 is said to have it?

Tuples (tuples) are also handy, and C # is now able to implement similar functions with a class library.

Optionals is basically the same as the C # nullable type, which is not the same as the wording, but also the same way. But there is an implicit parsing option in Swift (Implicity unwrapped optionals), with! tag, after the first payment, it is no longer necessary to judge the empty, can be used directly as a declared type.

Basic operators are basically the same as C, with a floating-point redundancy?

Interval operator, obviously Pascal series, C Series as if someone had used it, good things are worth learning. It is also divided into intervals (...). And half-interval (..)

String, Unicode encoding, and the meaning of the notation is the same as C.

Array, similar to C #, using the array<sometype> type, sometype[] is a simple notation. The array supports + = and interval operators, or it brings a lot of convenience.

For-in is the same as the foreach in C #

Dictionary<keytype, valuetype> just press. NET dictionary<k,v> to use it, not much difference.

See here, and see Swift in the use of new, is not the new and this is not a keyword?

Func method definition

Association value (associated values), something that seems to be the least understood at first glance, but it seems to be useful? It can associate a constant or variable value with an enumeration value, which can be used to get the associated constant or variable value directly from the enumeration value.

Class and struct are similar to C #, but members do not private,public that a type method (type Methods) is a static method,swift in C # that is represented by class Func. Class static member or static, not too make sense ah?

Class constructor with Init (), the parameters of the constructor are very peculiar, the internal and external names (in order to correspond to Objectivec), you can use convenience init () to call other constructors (such as: Self.init (name: "[Unnamed] ")) inherits with a colon, the parent class member with Super, can override the method, property, or property Observer, @final can prevent rewriting.

Anti-initialization (deinit)? (God named AH), just follow C # 's Dispose ().

The identity operator (= = =,!==) javascript?

Look at these today, the above is purely to learn now sell, if there are mistakes to correct.

Swift Contrast Learning (i)

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.