Re: Syntax of int Array in Message (OT: Objective-C Forum)
Re: Syntax of int Array in Message (OT: Objective-C Forum)
- Subject: Re: Syntax of int Array in Message (OT: Objective-C Forum)
- From: "Nick Kreeger" <email@hidden>
- Date: Tue, 16 Jan 2007 10:42:44 -0600
The reason why you are seeing the compiler warning for just the
|initWithArray:| method is because of your method of passing in your
int array. Double check your code, are you dereferencing your array?
Rather than passing my instance, why not pass my reference and use a
pointer for storing the array (less sexy suggestion), or just use the
NSArray/NSMutableArray interface that obj-c provides for you (sexier
suggestion). You could stash your int's in a NSNumber for storing in
the array.
Perhaps if you posted the declaration of your array and your call to
|initWithArray:|, the compiler warning could be identified easier.
- nick
I have a class "IntMatrix" in which I want to hold a two-dimensional
array of ints. It has the following init message which also sends a
message 'resetWithArray:' to itself:
/**
* Initialize this object with an array of ints.
*/
- (id)initWithArray:(int[])array
{
self = [super init];
if(self != nil)
{
[self resetWithArray:array];
}
return self;
}
/**
* Reset the int matrix of this object.
*/
- (void)resetWithArray:(int[])array
{
int n, i = 0, j = 0, last = CELLS_PER_ROW * CELLS_PER_COLUMN;
for(n = 0; n < last; n++)
{
matrix[i][j] = array[n];
if(++j == CELLS_PER_COLUMN)
{
j = 0;
i++;
}
}
}
The problem I am having is when I pass an int array in the init
message, I get the following warning: passing argument 1 of
'initWithArray:' from incompatible pointer type
However, when I pass the int array to the object with the
'resetWithArray:' message, it does not have this warning. Can someone
explain what the difference is and how I could correct this so that
there is no warning for using the 'initWithArray:' message? It seems
to work both ways but I get the warning when I pass the array in the
init message and it bothers me.
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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