Converting String(passed from objc) to Array in Javascript

Discussion in 'iOS Programming' started by ashwinr87, Jan 17, 2012.

  1. ashwinr87 macrumors member

    Joined:
    Mar 9, 2011
    #1
    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.
     
  2. chown33 macrumors 604

    Joined:
    Aug 9, 2009
    #2
    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.
     
  3. ashwinr87 thread starter macrumors member

    Joined:
    Mar 9, 2011
    #3
    I found out that
    Code:
    val
    itself is an array and I dont need to do anything..

     

Share This Page