As I wrote the @interface to an object today, I found myself wanting for but one thing:

- (NSArray <MyProtocol> *) foo;

Where – as if you hadn’t guessed it – the pointy bracket bit (the lengths to which I go to avoid typing out HTML entity names) would specify that all of the objects in the array returned by -foo conform to @protocol(MyProtocol). I then realised that this wouldn’t be quite as useful as I might think, but also decided that it wouldn’t be too hard even on the existing ObjC runtimes to come up with a nightmare function such as:

(Protocol *) objc_class_to_protocol(Class *cls);

…therefore meaning that my hitherto unattainable pipe dream:

- (NSArray <MythicalNSStringProtocol> *) foo;

may indeed be somewhat closer to realisability. Of course, with all of this being compile-time type checking (as with the similar beasties on Java) there would be no need to frob the runtime.

Update 2007-01-26T13:22: yes, I realise that the snippits above read "an NSArray or subclass, which also conforms to the MyProtocol protocol". I also know what I mean.

This entry was posted in objc. Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.