Swift learns the first day of the array

Source: Internet
Author: User

The first day of Swift learning:

1: Use of arrays

Definition of the array:

Let numbers = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]

2: Traversal of arrays

For num in numbers {

Print (num)

}

3: Also through subscript to make content

Let NUM1 = Numbers[0]

Let num2 = numbers[1]

4. Define variable non-volatile

' Let ' defines an immutable set of variables

' var ' defines a mutable array

5. Append content to a mutable array

Array1.append ("Wangwu")

6. When the array is initialized, if the value is assigned

If all content types are consistent during initialization, the content of that type is saved in the optional array

If all content types are inconsistent during initialization, the ' NSObject ' is saved in the optional array.

7. In Swift, the numbers can be added directly to the collection and no longer need to be converted to ' nsnumber '

8. In Swift, if you add a struct object to a collection, you still need to convert it to ' nsvalue '

Array2.append (Nsvalue (Cgpoint:cgpoint (X:10, y:10)))

9. No new values can be added before the array is instantiated

var array3: [String]

: Add value is not allowed before instantiation

Array3.append ("Laowang")

10. Must be an array of the same type to be able to merge

In development, the types of objects that are normally stored in arrays are the same!

11. Memory allocation

If you append an element to an array that exceeds the capacity, it is directly based on the existing capacity 2

Swift learns the first day of the array

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.