swift-Initial (2)

Source: Internet
Author: User

Logical branching simple experience
    • Periodic summary
      • SwiftThere is no concept in the C language 非零即真
      • The specific conditions of judgment must be indicated in the logical judgment
      • ifThe statement condition () can be omitted
      • But {} you can't omit it.
Tri-Mesh
    • Periodic summary
      • SwiftMaintains the 三目 same style as OC
Optional Walkthrough 1

    • Periodic summary

      • In Swift , not all object instantiation methods return values, and in real development you need to be aware of the return type of the instantiated function, for example:

        init?(string URLString: String)
      • If there is an ? indication that the modification method may not be instantiated to the correct object

      • This function returns an object that is called 可选项 , which may have a value, or it may not have a value
      • In actual development, it is necessary to judge this object and use it inside the branch ! to indicate that the object is actually present.
      • Compared to OC the development, especially in the daily practice, will be given a function to run the value, and in the actual run, once the condition is not satisfied, will flash back, so the user experience will be very bad

SwiftDesigners consider that because of the mandatory requirements of the type, it makes the code difficult to read, and therefore provides a workaround

Walkthrough 2

    • Periodic summary

      • if let 常量 = 可选构造函数the method used ensures that the internal constants of the branch must be valued
      • And no longer need to use it inside the branch!
      • This is Swift a very important use technique in the code.
    • Tips

      • Although the Swift method of type checking is provided, the Swift code to be written will need to be 优雅 practiced, otherwise the code with deep branch nesting level can be inadvertently found.
      • The relevant ? and ! choice can be aided by Xcode, but it is highly recommended that each time you encounter a prompt, think more and repeatedly
Walkthrough 3
    • Periodic summary
      • ??is a very useful operator that can be quickly nil judged
      • If the object is nil , use the ?? following value instead of the previous nil value to participate in the calculation
      • When used ?? , the entire section needs to use the () packaging
      • This technique is UITableView especially important in the data source approach

swift-Initial (2)

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.