iOS development empty array correct method

Source: Internet
Author: User

Nsarray and Nsmutablearray are two arrays in OBJC (immutable and mutable arrays),
In the daily development, often encounter the need to empty the array of circumstances, many people subconsciously think of nil This method, here is not advocated. Because if array = = nil is used, not only does the array be emptied, but also the memory is freed, and the object does not exist.
Never do this when you empty an array.

The right approach is to use removeallobjects; So you can get the results you want.

Using nil will delete the entire array, and using removeallobjects simply deletes the elements in the array:

[Nsarray removeallobjects];

iOS development empty array correct method

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.