【发布时间】:2011-07-22 09:52:00
【问题描述】:
我有一个名为“Book”的类,源代码如下:-
Book.h
#import <"UIKit/UIKit.h>
@interface Book : NSObject {
NSInteger bookID;
NSString *title; //Same name as the Entity Name.
NSString *author; //Same name as the Entity Name.
NSString *summary; //Same name as the Entity Name.
}
@property (nonatomic, readwrite) NSInteger bookID;
@property (nonatomic, retain) NSString *title;
@property (nonatomic, retain) NSString *author;
@property (nonatomic, retain) NSString *summary;
@end
Book.m
#import "Book.h"
@implementation Book
@synthesize title, author, summary, bookID;
-(void) dealloc {
[summary release];
[author release];
[title release];
[super dealloc];
}
@end
那么我可以在另一个班级里写:-
Book *aBook = [[Book alloc]init];
[aBook setValue:currentElementValue forKey:elementName];
如果是,那为什么?因为一般在 NSMutableDictionary 中使用 setvalue 和 forkey 来存储数据..
【问题讨论】:
标签: objective-c ios ios4