iOS traversal mode

Source: Internet
Author: User

nsarray* arrays = @[@ "1", @ "2", @ "3", @ "4", @ "5", @ "6", @ "7"];

Traversal method One

for (int i = 0; i < Arrays.count; i++)

NSLog (@ "Traverse one:%d", i);

Traverse Two

For (nsstring* I in arrays)

NSLog (@ "Traverse two:%@", i);

Traversal method Three

nsenumerator* enumerator = [Arrays Objectenumerator];

ID object;

while ((object = [Enumerator nextobject])! = nil)

NSLog (@ "Traverse three:%@", object);

Traversal method Four

nsenumerator* reverse = [arrays reverseobjectenumerator];

while ((object = [Enumerator nextobject])! = nil)

NSLog (@ "Traverse four:%@", reverse);

Traverse Five

[Arrays enumerateobjectsusingblock:^ (id _nonnull obj, nsuinteger idx, BOOL * _nonnull stop) {

NSLog (@ "Traverse five:%@", obj);

if ([obj isequaltostring:@ "5"])

*stop = YES;

}];

If you use blocks to execute, you can implement GCD to perform traversal operations concurrently, without having to write another program, and you cannot do this with other traversal methods.

iOS traversal mode

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.