NSData enumerateByteRangesUsingBlock sequence

The documentation for

[NSData enumerateByteRangesUsingBlock:]
makes no statement about the order in which the ranges in the NSData will be enumerated. For example, an implementation of this method would conform to the strict letter of its contract if it chose to enumerate the ranges backwards.


Is it in fact guaranteed that the block will be called with the ranges presented consecutively, from first to last, providing each byte once and once only and providing earlier bytes before later ones?

Replies

Is it in fact guaranteed that the block will be called with the ranges presented consecutively, from first to last, providing each byte once and once only and providing earlier bytes before later ones?

Yes. This behaviour is directly modelled on that of

dispatch_data_apply
, whose documentation does make that guarantee. I’d appreciate you filing a bug against the
NSData
documentation requesting that this be made clear. Please post your bug number, just for the record.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"