[cfe-dev] [] NSArray index and NSDictionary key syntax for other types?

Rick Mann rmann at latencyzero.com
Thu Feb 13 14:40:00 PST 2014


I just discovered the awesome [] operator for NSArray and NSDictionary. A number of places where I use -valueForKey: couldn't translate, because they aren't NSDictionary objects. I did a little reading, and learned that I need to implement -objectForKeyedSubscript:.

I was wondering if it would make sense to add a declarative attribute to indicate which methods should be used for indexed and keyed subscripts of some types. In other words, if I implement -valueForKey: on some class, I'd like to declare to the compiler that that should be used for [key] accesses (similarly, I might implement -setValue:forKey:). If the types are valid, it would use it.

Maybe this really isn't necessary given that I should be able to just implement -objectForKeyedSubscript:, but it would possibly remove an extra message send.

-- 
Rick



-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 204 bytes
Desc: Message signed with OpenPGP using GPGMail
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20140213/30082f4d/attachment.sig>


More information about the cfe-dev mailing list