35

What is __NSArrayI and __NSArrayM?

__NSArrayI(or M) cause "unrecognized selector" error.

How to convert to NSArray?


I did test to parse json, twitter api.

http://api.twitter.com/1/followers/ids.json?cursor=-1&screen_name=twitterapi

==> works fine. parsed object is NSCFDictionary class. (This dictionary contains __NSArrayM class)

http://api.twitter.com/1/statuses/user_timeline.json?&screen_name=twitterapi

==> error. parsed object is __NSArrayM class.

ChangUZ
  • 5,380
  • 10
  • 46
  • 64

3 Answers3

79

__NSArrayI is a code-word for an immutable array - that is, a "regular" NSArray which you cannot change.

__NSArrayM is a code-word for a mutable array - that is, NSMutableArray. In NSMutableArray, you can add and remove items.

Jason
  • 14,517
  • 25
  • 92
  • 153
  • 7
    Nice -- where do you find this knowledge? By just directly reading the source of the runtime? Or are there some sort of docs somewhere. – eric Jan 27 '13 at 23:07
  • 2
    The names are a good clue ("M" and "I" in the context of arrays couldn't mean much but mutable and immutable), but the best way is to inspect objects that you know to be NSArrays using object_getClass(). – Catfish_Man Apr 28 '13 at 05:36
  • @Catfish_Man six – 无夜之星辰 Aug 14 '17 at 08:17
5

These are classes of the private api. There is a project where you can see all classes of the private api. You are not allowed to use them inside an app for the app store but sometimes it is useful too see how to access the objects and also what kind of object it is. They cannot be converted. I think, getting these kind of objects inside the debugger is just the representation of internal classes, for the classes you are using inside your project. Knowing what kind of class it is, lets you also understand where to look for the problem inside your code.

Here you can see a short lookup of both:

__NSArrayI

enter image description here

__NSArrayM

enter image description here

Alex Cio
  • 6,014
  • 5
  • 44
  • 74
2

It is private classes. You shouldn't want to access them or moreover convert them.

If I'm not mistaken NSArray is subclass of _NSArray.

If you are adding/removing some objects to/from your array check that it is of mutable type : NSMutableArray

Nekto
  • 17,837
  • 1
  • 55
  • 65