Re: Inserting an (int) into an NSMutableArray
Re: Inserting an (int) into an NSMutableArray
- Subject: Re: Inserting an (int) into an NSMutableArray
- From: SA Dev <email@hidden>
- Date: Wed, 3 Aug 2005 15:02:44 -0400
Adam:
Cocoa containers (like an NSArray and NSMutableArray) require that
you add objects, not primitives. If you want to add an integer,
create an NSNumber instance like so:
NSNumber * myNumber = [NSNumber numberWithInt:myInt];
[myArray addObject:myNumber];
or for shorthand:
[myArray addObject:[NSNumber numberWithInt:myInt]];
Hope this helps.
On Aug 3, 2005, at 2:32 PM, Adam Raney wrote:
I am showing my lack of knowledge of ObjC here, but I'm learning.
I am trying to insert an int into an NSMutableArray, but getting an
error.
My int is an instance variable of my controller class. I am trying
to add the int to an instance variable NSMutableArray of another
class (already properly instantiated) through this process
[myObject addItemToArray: myInt];
Which in turn calls this method:
- (void) addItemToArray: (id) newItem
{
[myArray addObject: newItem];
}
I get the following error in the debugger:
[NSCFArray addObject:]: attempt to insert nil
I know this is some stupid rookie mistake, that I am missing some
fundamental understanding here, but could someone be so kind as to
point out the flaw of sending an int directly in such a manner?
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
40silentalcove.net
This email sent to email@hidden
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden