Comparison of playground and OC syntax in 2.Swift

Source: Internet
Author: User


1.playground 1.1 IntroductionAt the WWDC conference in 2014, Apple officially unveiled swift--'s new programming language for Apple's mobile device software development effort. To match the birth of the new language, Xcode 6 adds a new feature called playgrounds-a set of interactive workspaces where developers can write swift code and get real-time performance feedback without having to run it in a device or simulator. This is undoubtedly a good addition to Xcode, and now you can quickly and easily master real-time performance in an experimental way before you formally add your own code to the main code base.1.2 Hints
    • Some of the official learning resources are provided in theplaygroundform of
    • Create a file of your ownplaygoundand be able to discover grammar changes the first time each version is upgraded
Enter the Welcome interface interface 2left : code area Right : run result display area I call it: what you see is what you getInterface 3 directly See development effects without compilingfunction : Convenient for beginners to drill quickly, easy to test code  2. First experience, different from OC
/*syntax : InitializeOC alloc/initwithxxx alloc/initSwift class name (XXX:) ()  method call Point syntax call method OC: [Uicolor redcolor];Swift:UIColor.redColor enumeration : Oc:uibuttontypecontactadd     Swfit:. separate Span style= "font:12.0px ' Heiti SC light '; Font-variant-ligatures:no-common-ligatures; Color: #008400; " > Quick and practical Check the enumeration -> Enter- > Right-click ->. Span style= "font:12.0px ' Heiti SC light '; Font-variant-ligatures:no-common-ligatures; Color: #008400; " > select enum Enumeration . The first half of the section can be omitted Note omitting the first half of the enumeration may not only prompt   Swift Language is more concise */ import UIKit  var str = "Hello, Playground"  Letv =UIView(Frame:cgrectmake (0, 0, 100, 100 v. BackgroundColor = uicolor. Redcolor()  let BTN = uibutton< Span style= "font:12.0px Menlo; Font-variant-ligatures:no-common-ligatures; " > (type:. contactadd) btn. center = v. center v. Addsubview(btn)  //let image = UIImage (named: "xxxx")
3. Summary
  • Not in Swiftmain.m,@UIApplicationMainIt's a program entry.
  • Only files in Swift.swift, no.h/.mdistinction between files
  • In Swift, a class is enclosed in a pair{}, with no@implementation@end
  • There is no semicolon at the end of each statement, and in other languages, semicolons are used to distinguish between different statements.

    • In Swift, it's usually a line of code, so you don't use semicolons
  • A quick comparison with OC syntax

    • corresponding in OCalloc / init()
    • corresponding in OCalloc / initWithXXX(XXX: )
    • class function calls in OC, in Swift, directly using the.
    • In Swift, the vast majority can be omittedself., the recommendation is generally not written, can improve the understanding of the context (closures will be realized)
    • Enumeration types in OC are usedUIButtonTypeContactAdd, while Swift separates, Operation Hotkeys:回车 -> 向右 -> .
      • In Swift, the prefix of an enumeration type can be omitted, such as:.ContactAdd, but: many times no smart hints
    • Listener method, directly using string to cause
    • In Swift, useprint()an alternative in OCNSLog


Comparison of playground and OC syntax in 2.Swift


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.