Casting in objective-c

10,013

Your dictionary doesn't contain an NSString. If you'd like the string representation of the object, you could call the object's description selector, e.g.:

NSString *post = [[[temp objectAtIndex:i] valueForKey:@"POSTDESCRIPTION"] description];
Share:
10,013
Jason
Author by

Jason

I am the Manager of Application Programming for the Informatics group at Purdue University where I'm responsible for providing development in the areas of research, teaching, and learning. My experience includes application development, project management, and driving new and creative Web and Mobile strategies. The work of my group has been featured by the New York Times, CNET, and The Chronicle of Higher Education.

Updated on June 04, 2022

Comments

  • Jason
    Jason almost 2 years

    I have a dictionary object that I am pulling data out of. The field is supposed to be a string field but sometime all that it contains is a number. I get the info using:

    NSString *post = [[temp objectAtIndex:i] valueForKey:@"POSTDESCRIPTION"];
    

    So it is going into a string object. However, when I try to assign that to a cell's text via:

    cell.textLabel.text = post;
    

    I get a the following error:

    'NSInvalidArgumentException', reason: '*** -[NSDecimalNumber isEqualToString:]: unrecognized selector sent to instance 0x4106a80'
    2009-10-20 13:33:46.563
    

    I have tried casting it with the following ways to no avail:

    NSString *post = [[[temp objectAtIndex:i] valueForKey:@"POSTDESCRIPTION"] stringValue];
    NSString *post = (NSString *)[[temp objectAtIndex:i] valueForKey:@"POSTDESCRIPTION"];
    cell.textLabel.text = [post stringValue];
    cell.textLabel.text = (NSSting *)post;
    

    What am I doing wrong?