NSMutableArray insertObject:(id) atIndex:int inserting a void ptr?

NSArrays expect to hold objective-C objects conforming to the NSObject protocol. If you wish to wrap a pointer, use NSValue.

Up vote 0 down vote favorite share g+ share fb share tw.

C++ cocoa nsmutablearray objective-c++ link|improve this question asked Jan 27 '11 at 18:22Rohan 289212 64% accept rate.

This does not look like C++ to me. – John Dibling Jan 27 '11 at 18:25 @John It's objective-C++, C++ with all the features of objective-C or vice versa. – cobbal Jan 27 '11 at 18:30.

NSArrays expect to hold objective-C objects conforming to the NSObject protocol. If you wish to wrap a pointer, use NSValue: myArray insertObject:NSValue valueWithPointer:node atIndex:idx; You are manually responsible for all memory management of that pointer, as objective-C can't reference count it in the usual way.

Its working :) with my case – Rohan Jan 28 '11 at 9:35.

NSMurableArray only accepts Objective-C objects (hence the argument type of addObject: being id). Are you on the Mac or iOS? If you're on the Mac, You might want to look at NSPointerArray.

You might also be able to be CFMutableArray with custom callback functions, but I haven't tried this myself.

...or take cobbal's advice and use NSValue, which I always forget about... – Jablair Jan 27 '11 at 18:34 I've never used NSPointerArray, but it does look like a good fit for this problem. The memory management helper functions would probably be useful, I don't think NSValue has the equivalent. Also, I think it's safe to assume Mac from "NSTable/NSOutliveVIew" – cobbal Jan 27 '11 at 20:03 Yeah, that should've clicked, shouldn't it?

I looked for a Mac or iPhone tag and didn't see one. – Jablair Jan 27 '11 at 21:12 I tried with NSPointerArray, following is my code snippet \n pCTArray = NSPointerArray allocinitWithOptions:NSPointerFunctionsObjectPersonality; then set the size pCTArray setCount:10; after that try to insert 10 objects in while loop but I am always getting EXEC_BAD_SIGNAL , am I missing something – Rohan Jan 27 '11 at 6:42.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions