iOS中新的遍历方法

- (void)enumerateObjectsUsingBlock:(void (NS_NOESCAPE ^)(ObjectType   obj ,NSUInteger idx,BOOL*stop))blockAPI_AVAILABLE(mac os(10.6),  ios(4.0), watch os(2.0), tv os(9.0));

方法描述:

Executes a given block using each object in the array, starting with the first object and continuing through the array to the last object.

执行一个给定的block,使用数组中的每个对象。以第一个元素开始,继续直到最后一个元素。

If the block parameter is nil this method will raise an exception. Values allocated within the block will be deallocated after the block is executed. Use retain to explicitly maintain those values.

如果定义的block为nil,将会抛出异常。当block执行完毕后,block中allocation的值将会释放。使用retain来拥有想要拥有的值。

This method executes synchronously.

这个方法的是同步执行的。

参数描述:

block:

The block to apply to elements in the array.

在数组中申请元素的block。

The block takes three arguments:

block拥有三个参数。

obj

The element in the array.

数组中的元素。

idx

The index of the element in the array.

数组中元素的index。

stop

A reference to a Boolean value. The block can set the value to YES to stop further enumeration of the array. If a block stops further enumeration, that block continues to run until it’s finished. The stop argument is an out-only argument. You should only ever set this Boolean toYES within the block.

是一个bool值的引用,block可以把这个值设置为yes来阻止接下来的数组遍历。如果block阻止了遍历,block会把此次遍历执行完。stop仅仅是一个跳出参数,你只能设置它为yes。

你可能感兴趣的:(iOS中新的遍历方法)