我正在编写API,我坚信将尽可能多的类型安全性放入API中.有没有@protocol像NSSet,NSArray等在for (foo in bar) {..}样式循环中将其标记为"可迭代"的东西?目前我有这样的事情:
- (void) doSomethingWith:(id)someItems;
Run Code Online (Sandbox Code Playgroud)
当我想要沿着这些方向做点什么时:
- (void) doSomethingWith:(id <NSIterableCollection>)someItems;
Run Code Online (Sandbox Code Playgroud)
它可行吗?是否想要它让我成为某种静态打字的weanie谁没有做Obj-C的地方?;-)
想要使用标准Objective-C fast enumeration(for..in构造)支持枚举的对象必须阻止NSFastEnumeration.NSArray,NSDictionary,NSSet和NSEnumerator采用该协议.