Re: How can I get rid of this message?
Re: How can I get rid of this message?
- Subject: Re: How can I get rid of this message?
- From: WT <email@hidden>
- Date: Thu, 2 Jul 2009 04:48:52 +0200
On Jul 2, 2009, at 4:41 AM, Agha Khan wrote:
I am adding a object (somedata)
for (int i = 0; i < 7; i++)
{
SomeData* singleNutData = [[SomeData alloc] init];
[NutArray addObject: SomeData];
}
I am getting warning.
NSArray may not respond to -addObject.
(Message without a matching method signature will be assumed to
return id and accept '...' as arguments.)
Am I am doing something wrong?
I am new to Apple development and how can I get rid of this message.
Thanks in advance.
Best regards
-Agha
NSArray is a class representing array objects that *cannot* be
changed, once they're created and initialized. You're trying to change
one by adding a new object to the array, and the compiler is telling
you that NSArray objects do not respond to the message that adds an
object. Makes sense, no?
What you need is to declare your array as an instance of
NSMutableArray, which is the class that represents arrays which you
*can* change.
You should read the documentation for both NSArray and NSMutableArray
to better understand the differences between the two (for instance,
what messages NSMutableArray responds to which NSArray doesn't).
Wagner
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden