I am using CoreData and it's returning a NSMangedObject. I have taken it into NSSet and now i want to take the value out and display it. Here's the code snippets:
NSManagedObject *financialsData = [serverResult valueForKey:@"financials"];
NSSet *financiers = [financialsData valueForKey:@"planFinanciers"];
for (NSManagedObject *financier in financiers)
{
开发者_如何学编程}
Please help.
You haven't told us anything about the attributes and relationships that a particular financier has, but in general you can use accessors or KVC to get the data from each object:
NSManagedObject *financialsData = [serverResult valueForKey:@"financials"];
NSSet *financiers = [financialsData valueForKey:@"planFinanciers"];
for (NSManagedObject *financier in financiers)
{
// Assuming there are 'name' and 'netWorth' attributes...
NSLog(@"Name: %@\tNet Worth:%.2f", financier.name, financier.netWorth);
// ...or...
NSLog(@"Name: %@\tNet Worth:%.2f", [financier valueForKey:@"name"], [[financier valueForKey@"netWorth"] floatValue]);
}
Don't take my word for it, though... read Managed Object Accessor Methods.
精彩评论