I'm writing an API, and I'm a firm believer of putting as much type safety as possible into APIs. Is there a @protocol
for things like NSSet, NSArray, etc that marks it as "iterable" in a for (foo in bar) {..}
style loop? At the moment I've got something like this:
- (void) doSomethingWith:(id)someItems;
When I'd like to have something along these lines:
- (void) doSomethingWith:(id <NSIterableCollection>)someItems;
Is it doable? Does wanting it make me some kind of static-typing weanie who has no place doing Obj-C? ;-)
Objects that want to support enumeration using the standard Objective-C fast enumeration
(for..in
construct), must impelement the NSFastEnumeration
. NSArray
, NSDictionary
, NSSet
and NSEnumerator
adopt this protocol.
Yes. NSFastEnumeration.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With