Search code examples
iosobjective-cnsarrayunrecognized-selector

Separate a String By Semicolon


I am using following code to separate a string into multiple strings and getting an error

NSArray *arr = [randomStr componentsSeparatedByString:@";"];

Error:

-[__NSDictionaryM componentsSeparatedByString:]: unrecognized selector sent to instance 0x1758f230 -[__NSDictionaryM componentsSeparatedByString:]: unrecognized selector sent to instance 0x1758f230

This is my Sample Data

NSArray *data = {
    {
    name = "name1";
    address = "RWP";
    ID = 0;
},
    {
    name = "name2";
    address = "RWP";
    ID = 1;
},
    {
    name = "name3";
    address = "RWP";
    ID = 2;
},}

NSString *randomStr = data[0];

What's wrong in my code


Solution

  • You have an array of dictionaries, not strings. There is nothing to split.

    You want something like this:

    NSDictionary *dict = data[0];
    NSString *name = dict[@"name"];
    NSString *address = dict[@"address"];