I changed my NSArray into an NSMutableArray, the "count" into
lengthObject and it's perfect!
- (void)setArrayOfSteps:(id)object
{
id lengthObject = [object valueForKey:@"length"];
unsigned length = [lengthObject isKindOfClass:[NSNumber class]] ?
[lengthObject unsignedIntValue] : 0;
arrayOfSteps = [[NSMutableArray alloc] initWithCapacity:length];
unsigned i;
for (i = 0; i < length; ++i) {
id element = [object webScriptValueAtIndex:i];
if (element)
[arrayOfSteps addObject:element];
}
NSLog(@"arrayOfSteps filled with %d elements !", [arrayOfSteps count]);
}
Mathieu Thouvenin
On Aug 29, 2007, at 18:14 , Darin Adler wrote:
If you look at the documentation in the WebScriptObject.h header
file, you'll see that an NSArray does turn into a JavaScript array
object, but a JavaScript array object does not turn into an
NSArray. There are many reasons for this, one being that there are
many different kinds of objects in JavaScript that act like arrays,
and luckily it's easy to cope with. You can modify your code to be
something like this:
- (void)setArrayOfSteps:(id)object
{
id lengthObject = [object valueForKey:@"length"];
unsigned length = [lengthObject isKindOfClass:[NSNumber
class]] ? [count unsignedIntValue] : 0;
arrayOfSteps = [[NSArray alloc] initWithCapacity:length];
unsigned i;
for (i = 0; i < length; ++i) {
id element = [object webScriptValueAtIndex:i];
if (element)
[arrayOfSteps addObject:element];
}
NSLog(@"arrayOfSteps filled with %u elements !", [arrayOfSteps
count]);
}
Hope that helps.
-- Darin
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webkitsdk-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/webkitsdk-dev/email@hidden