Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

ashwinr87

macrumors member
Original poster
Mar 9, 2011
81
0
I am passing a string from objective C to javascript in this way -

Code:
NSArray *array = [NSArray arrayWithObjects:@"10",@"9",@"8", nil];
string = [[array valueForKey:@"description"] componentsJoinedByString:@","];

[graphView stringByEvaluatingJavaScriptFromString:[NSString stringWithFormat:@"methodName2([%@])", string]];

and in my javascript I am trying to convert the string into an array by -

Code:
function methodName2(val)
            {
                var b = val;
                var temp = new Array();
                temp = b.split(',');

                alert(temp);
            }

The way I am using to convert does not seem to work. I am wondering if this is because there is a mismatch in the way the javascript understands the "string" being sent to it?

It would be great if someone could help me out with this.
 
What is the actual string as it appears in JavaScript? If it's not a string, then you need to say "It's not a string", and then identify what it is.

What is the actual result after the split()?

Does the expression evaluate at all? Do you need a semicolon somewhere? Or maybe some quotes?

What other JavaScript have you tried running from Objective-C? Are you sure you understand the basics of evaluating JavaScript?


Saying only "does not seem to work" is remarkably uninformative about what is actually happening. There are billions and billions of ways that something can "not seem to work". If you expect to debug this, you need to be specific about what actually happens.
 
I found out that
Code:
val
itself is an array and I dont need to do anything..

What is the actual string as it appears in JavaScript? If it's not a string, then you need to say "It's not a string", and then identify what it is.

What is the actual result after the split()?

Does the expression evaluate at all? Do you need a semicolon somewhere? Or maybe some quotes?

What other JavaScript have you tried running from Objective-C? Are you sure you understand the basics of evaluating JavaScript?


Saying only "does not seem to work" is remarkably uninformative about what is actually happening. There are billions and billions of ways that something can "not seem to work". If you expect to debug this, you need to be specific about what actually happens.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.