2011-07-11 50 views
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的呢?

回答

0

是的,你不能直接使用KVC訪問數組。 但是,您可以使用總計像@sum,@avg來計算總和,平均值

例如:@ sum.message_count會給你數組中所有消息的總消息數。你不必爲此寫任何循環。