开发者

How to access values from NSSet?

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜