Can I restrict the NSMutableArray object type?

2019-09-06 12:36发布

问题:

I want the NSMutableArray only store "MyObject" only... ...instead of any objects. How can I do this? thz.

回答1:

There is no concept like C# Generics or C++ Templates in Objective-C, as discussed here before, but you could create a class which exposes an array and has add and remove-methods which take only your object type (see here).