Swift Study Notes (2): attributes, tuples

Source: Internet
Author: User

1. getter and setter of the attribute

// Set the computing property: it is not a real storage value, but the VaR Subtotal: Double calculated every time using other values {// getter: get the total value through the total and taxpct calculation get {return total/(taxpct + 1)} // setter: updated related values (for example, the value of total and taxpct is set based on newsubtotal) Set (newsubtotal ){//...}}

Ii. tuples | tuples

// Create an unamed tupleslet tipandtotal = (4.00, 25.19) // create a named tupleslet tipandtotalnamed = (tipamt: 4.00, total: 25.19) tipandtotalnamed. tipamttipandtotalnamed. total // create tupleslet tipandtotalnamed :( tipamt: Double, total: Double) = (4.00, 25.19)

Returned tuples

Let Total = 21.19let taxpct = 0.06let subtotal = total/(taxpct + 1) // here, the returned type is func calctipwithtippct (tippct: Double)-> (tipamt: Double, total: double) {Let tipamt = subtotal * tippct let finaltotal = total + tipamt return (tipamt, finaltotal)} calctipwithtippct (0.20)

III,

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.