Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is __NSArrayI and __NSArrayM? How to convert to NSArray?

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.

like image 467
ChangUZ Avatar asked Oct 07 '11 08:10

ChangUZ


People also ask

How do I create an NSArray in Objective C?

Creating NSArray Objects Using Array Literals In addition to the provided initializers, such as initWithObjects: , you can create an NSArray object using an array literal. In Objective-C, the compiler generates code that makes an underlying call to the init(objects:count:) method.

What is difference between NSArray and NSMutableArray?

The primary difference between NSArray and NSMutableArray is that a mutable array can be changed/modified after it has been allocated and initialized, whereas an immutable array, NSArray , cannot.

What is NSArray?

NSArray is an immutable Objective C class, therefore it is a reference type in Swift and it is bridged to Array<AnyObject> . NSMutableArray is the mutable subclass of NSArray .

Can NSArray contain nil?

arrays can't contain nil.


2 Answers

__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.

like image 67
Jason Avatar answered Oct 03 '22 04:10

Jason


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

like image 40
Alex Cio Avatar answered Oct 03 '22 05:10

Alex Cio