Исправление для вашего кода:
id anObject = [appDelegate.currentDeailedObject objectAtIndex:0];
int commentId = [anObject id];
NSString *commentType = [anObject type];
Обратите внимание на пропущенный «*» после «id» (id уже представляет ссылку) и пропущенный «valueForKey» (это метод внутри NSDictionary, который возвращаетзначение, которое представлено предоставленным ключом).
В общем, этот код должен работать,Но я бы посоветовал вам создать суперкласс или протокол, который будет иметь 2 метода, которые вам нужны (например, «id» и «type»).
Например (суперкласс):
@interface MyComment : NSObject
{
NSInteger commentId;
NSString *_commentType;
}
@property (nonatomic) NSInteger commentId;
@property (nonatomic, copy) NSString *commentType;
@end
@implementation MyComment
@synthesize commentId, commentType = _commentType;
- (void)dealloc {
[_commentType release];
[super dealloc];
}
@end
// sample use
@interface MyCommentNumberOne : MyComment
{
}
@end
Другой пример (протокол):
@protocol CommentPropertiesProtocol
@required
- (NSInteger)commentId;
- (NSString *)commentType;
@end
// sample use
@interface MyCommentNumberOne : NSObject <CommentPropertiesProtocol>
{
NSInteger commentId;
NSString *_commentType;
}
@end
@implementation MyCommentNumberOne
- (NSInteger)commentId {
return commentId;
}
- (NSString *)commentType {
return _commentType;
}
- (void)dealloc {
[_commentType release];
[super dealloc];
}
@end