Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Sending a Javascript Array in Cocoa



Hello Everybody!

I have a problem for a couple of days now and even after searching google for hours I haven't found a solution. That's why I'm asking some help here!

Basically, I'm using the _javascript_ <-> Cocoa scripting bridge to send data from my Cocoa/Webkit app to my HTML/_javascript_ page, and vice-versa. The problem is that I have a _javascript_ array in my webpage (the array contains only strings) and I want to send it in my Cocoa app and it doesn't work.

Here is what I have in my webpage:

var myArray = new Array();
var i;
// Fill the array with all the strings
for (i=0 ; i < myMaxNumber ; i++)
{
myArray[i] = myObject.getDescriptionString();
}
var controller = window.appcontroller;
controller.setArrayOfSteps_(myArray);
In my Cocoa app I have:

- (void)webView:(WebView *)sender windowScriptObjectAvailable: (WebScriptObject *)windowScriptObject 
{
scriptObject = [myWebView windowScriptObject];
// send "self" to access the setArrayOfSteps method in _javascript_
[scriptObject setValue:self forKey:@"appcontroller"];
}

- (void)setArrayOfSteps:(NSArray *)array
{
// Init my NSArray with the _javascript_ array
arrayOfSteps = [[NSArray alloc] initWithArray:array];
NSLog(@"arrayOfSteps filled with %d elements !", [arrayOfSteps count]);
}

When I run my app everything works great except that I have this error in the Debugger console:

*** -[WebScriptObject count]: unrecognized selector sent to instance 0x3ebf430

It seems that the NSArray is not correctly initialized with the _javascript_ Array. Is it normal? Is it possible to do what I'm doing (sending a _javascript_ Array to an NSArray)?

Thanks a lot for your help!

Regards,

Mathieu Thouvenin
 _______________________________________________
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

This email sent to email@hidden



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.