Is there any way to enforce typing on NSArray, NSMutableArray, etc.?

Nobody’s put this up here yet, so I’ll do it!

Tthis is now officially supported in Objective-C. As of Xcode 7, you can use the following syntax:

NSArray<MyClass *> *myArray = @[[MyClass new], [MyClass new]];

Note

It’s important to note that these are compiler warnings only and you can technically still insert any object into your array. There are scripts available that turn all warnings into errors which would prevent building.

Leave a Comment