I have the following class:
@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
Now I am trying to access a particular topics name using:
RKObjectMapping* mapping = [RKObjectMapping mappingForClass:[TTTableTextItem class]];
[mapping mapKeyPath:@"topics.na开发者_JS百科me" toAttribute:@"text"];
[mapping mapKeyPath:@"topics.topicNavURL" toAttribute:@"URL"];
However, this fails as it says that it doesn't find name as topics is a NSArray. Is there a way to do KVC if I am dealing with array? Is it just NSString's then?
Yes, you cannot access an array directly using KVC. However you can use aggregates like @sum, @avg to calculate the sum, average
For ex: @sum.message_count will give you the total message count of all messages in the array. You don't have to write any loop for that.
精彩评论