Search code examples
ioscore-datansset

nsset valueforkey returns with "{( the value I need )}"


In CoreData this returns me text i need placed between {( ... )}

NSSet *abc = self.file.abc;
NSString *name = [abc valueForKey:@"name"];

cell.nameLabel.text = [NSString stringWithFormat:@"%@",name ];

How to get the correct text?


Solution

  • When you call valueForSet: on a set, it returns "a set containing the results of invoking valueForKey: on each of the receiving set's members."

    This means that your name variable is actually pointing to a set instead of a string.

    What you are seeing is simply the string description of a set.


    Assuming that your set only contains one object, you can get that to that object by calling anyObject on the set. Then you can get the name of that object.