0

我有以下课程:

@interface Topics : NSObject {
    NSNumber * _until_id;
    NSArray * _topics;
}

@property (nonatomic, retain) NSNumber * until_id;
@property (nonatomic, retain) NSArray * topics;
@end

/////////////////////////////////////////////////////////////////////////

@class Login;

@interface Topic : NSObject {
    NSString * _name;
    Login * _creator;
    NSNumber * _message_count;
    NSNumber * _date_latest_message;
    NSNumber * _date_created;
    NSNumber * _tracked;
    NSNumber * _unread;
    NSNumber * _tid;
    NSString * _kind;
    NSNumber * _id;
}

@property (nonatomic, retain) NSString * name;
@property (nonatomic, retain) Login * creator;
@property (nonatomic, retain) NSNumber * message_count;
@property (nonatomic, retain) NSNumber * date_latest_message;
@property (nonatomic, retain) NSNumber * date_created;
@property (nonatomic, retain) NSNumber * tracked;
@property (nonatomic, retain) NSString * kind;
@property (nonatomic, retain) NSNumber * unread;
@property (nonatomic, retain) NSNumber * tid;
@property (nonatomic, retain) NSNumber * gid;
@property (nonatomic, readonly) NSString* topicNavURL;

@end

现在我正在尝试使用以下方法访问特定主题名称:

RKObjectMapping* mapping = [RKObjectMapping mappingForClass:[TTTableTextItem class]];
 [mapping mapKeyPath:@"topics.name" toAttribute:@"text"];
 [mapping mapKeyPath:@"topics.topicNavURL" toAttribute:@"URL"];

但是,这失败了,因为它说它找不到名称,因为主题是 NSArray。如果我正在处理数组,有没有办法做 KVC?那么它只是NSString的吗?

4

1 回答 1

0

是的,您不能使用 KVC 直接访问数组。但是,您可以使用 @sum、@avg 等聚合来计算总和、平均值

例如:@sum.message_count 将为您提供数组中所有消息的总消息数。您不必为此编写任何循环。

于 2011-07-11T10:18:26.137 回答