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