Can I put different types of objects in the same NSMutableArray?

后端 未结 3 761
别那么骄傲
别那么骄傲 2021-02-14 00:19

I have classes A and B.
Can I put these classes in the same NSMutableArray without problems in future?

Example:

NSMutableArray *maincoll = [[NSMutabl         


        
相关标签:
3条回答
  • 2021-02-14 01:10

    Yes.

    This may be the shortest answer I've ever posted.

    0 讨论(0)
  • 2021-02-14 01:11

    You can put objects of different classes. They just need to inherit from NSObject. Don't forget to release after adding to the array.

    0 讨论(0)
  • 2021-02-14 01:24

    Yes. No limitations. The only thing you have to be careful of is when you retrieve items from the array to verify their class (if necessary) before starting to use them.

    0 讨论(0)
提交回复
热议问题