Swift language----tuples

Source: Internet
Author: User

Tuples are unique in swift, and there is no correlation type in OC

/*

It is a data structure, which is widely used in mathematics.

Similar to arrays or dictionaries

You can define a set of data

The data that makes up the tuple type is called the "element"

*/

The difference between a tuple, an array, and a dictionary

1. Use arrays to define a set of data

Let Infoarray = ["Wenjian", 18,1.88]

Gets the elements in the array

Let NameArray = infoarray[0]

2. Use a dictionary to define a set of data

Let infodict = ["Name": "Wenjian", "age": +, "height": 1.88]

Get the elements in the dictionary

Let namedict = infodict["Name"]

3. Use tuples to define a set of data

Let Infotuple = ("Wenjian", 18,1.88)

Gets the elements in the tuple

Let nametuple = infotuple.0

4. Using tuples to define a network request error

Array

Let Errorarray = ["Not Found", 404]

Dictionary

Let errodict = ["erromsg": "Not Found", "Errocode": 404]

Meta-group

Let Errotuple = ("Not Found", 404)

errotuple.0

Alias all elements in a tuple

Let ErroTuple1 = (erromsg: "Not Found", errocode:404)

Errotuple1.erromsg = = erroTuple1.0

Errotuple1.errocode = = erroTuple1.1

The tuple's alias is the name of the tuple

Let (erromsg,errocode) = ("Not Found", 404)

Erromsg

Errocode

Swift language----tuples

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.