Re: A simple doubt about array
Re: A simple doubt about array
- Subject: Re: A simple doubt about array
- From: Adam Leonard <email@hidden>
- Date: Tue, 10 Jun 2008 17:33:34 -0700
If you do want to make use of some of the nice features of NSArray
that C arrays don't have, it is trivial to add a category to NSArray
that makes object retrieval easier. See http://developer.apple.com/documentation/Cocoa/Conceptual/ObjectiveC/Articles/chapter_4_section_1.html
An example implementation might look something like this (not tested,
and no type checking which you should probably do):
@implementation NSArray (PuzzleBoardAdditions)
- (id)objectAtRow:(NSUInteger)row column:(NSUInteger)column
{
return [(NSArray *)[self objectAtIndex:row] objectAtIndex:column];
}
@end
and (after importing the category interface), you can call it with one
clean line like [array objectAtRow:0 column:0]
Adam Leonard
On Jun 10, 2008, at 12:22 PM, Sidnei Vladisauskis wrote:
Hi,
I'm making in a simple puzzle...It´s working perfect, but I'm with
doubt about bidimensional array.
My code is:
NSMutableArray *array = [[NSMutableArray alloc] init];
for(int i = 0; i<5; i++){
NSMutableArray *arrayLine = [[NSMutableArray alloc] init];
for(int ii = 0; ii<5; ii++){
[arrayLine addObject:@"str"];
}
[array addObject:arrayLine];
}
It's right, ok?
For acces my object in my array I'm using this:
NSArray *tempArray = [array objcetAtIndex:0];
NSString *myStrig = [tempArray objectAtIndex:0];
This code return me the first object of the bidimensional array, but
there other way for return my object?
In other linguages the more simples is using:
myObject = array[0][0];
And for replace is:
array[0][0] = newObject;
And in objective-C I use the method "replaceObjectAtIndex" ok?
Thanks... _______________________________________________
Do not post admin requests to the list. They will be ignored.
Objc-language mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden
_______________________________________________
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