Ios 哪种方法是初始化NSMutableDictionary的正确方法。请任何人在这里纠正我
我正在尝试在我的类中创建NSMutableDictionary。我在stackoverflow上读了很多帖子来理解其中的区别。但现在我完全糊涂了。因此,任何人都可以纠正我,哪一种是在我的课堂上初始化NSMutableDictionary的正确方法。我必须在我的应用程序的许多地方访问这个词汇表。所以建议我使用变量初始化的好方法Ios 哪种方法是初始化NSMutableDictionary的正确方法。请任何人在这里纠正我,ios,ios4,ios5,Ios,Ios4,Ios5,我正在尝试在我的类中创建NSMutableDictionary。我在stackoverflow上读了很多帖子来理解其中的区别。但现在我完全糊涂了。因此,任何人都可以纠正我,哪一种是在我的课堂上初始化NSMutableDictionary的正确方法。我必须在我的应用程序的许多地方访问这个词汇表。所以建议我使用变量初始化的好方法 /// .h file @interface ActiveFeeds : NSObject { } @property (nonatomic, copy) NSMutab
/// .h file
@interface ActiveFeeds : NSObject {
}
@property (nonatomic, copy) NSMutableDictionary *invDictionary;
@property (nonatomic, retain) NSString *filePath;
@end
@implementation ActiveFeeds
@synthesize filePath;
@synthesize invDictionary;
- (id)init{
self = [super init];
if (self != nil){
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:self.filePath];
self.invDictionary = [dictionary mutableCopy];
dictionary release];
}
return self;
}
/* And use self.invDictionary all in the application */
- (void)setObjectAtKey:(NSMutableDictionary *)objectDic atKey:(NSString *)setKey{
[self.invDictionary setObject:objectDic forKey:setKey];
}
- (void)dealloc {
[self.invDictionary release];
[self.filePath release];
[super dealloc];
}
@end
或者像这样
@interface ActiveFeeds : NSObject {
NSMutableDictionary *invDictionary;
NSString *filePath;
}
@end
@implementation ActiveFeeds
- (id)init{
self = [super init];
if (self != nil){
NSMutableDictionary *dictionary = [[NSMutableDictionary alloc] initWithContentsOfFile:filePath];
invDictionary = [dictionary mutableCopy];
[dictionary release];
}
}
return self;
}
/* And use invDictionary all in the application */
- (void)setObjectAtKey:(NSMutableDictionary *)objectDic atKey:(NSString *)setKey{
[invDictionary setObject:objectDic forKey:setKey];
}
- (void)dealloc {
[invDictionary release];
[filePath release];
[super dealloc];
}
@end
请任何人帮我找到使用变量的正确方法
- (id)initWithFilePath:(NSString *)path{
self = [super init];
if (self != nil){
self.filePath = path;
self.invDictionary = [NSMutableDictionary dictionaryWithContentsOfFile:path];
}
return self;
}
也
那么,您试图指向哪个接口。如果我像这样初始化,我将如何调用“-voidsetObjectAtKey”和“-voiddealloc”…[实例setObjectsAtKey:]或者我不理解您的意思
- (void)dealloc {
[invDictionary release];
[filePath release];
[super dealloc];
}