相关疑难解决方法(0)

创建一个常量字典对象

我想完成这篇文章中正在做的事情:Objective-C中的常量

但是,我想构建一个NSDictionary.

如果我这样做:

constants.h

extern NSArray *const mFooKeys;
extern NSArray *const mFooObjects;
extern NSDictionary *const mFooDictionary;
Run Code Online (Sandbox Code Playgroud)

constants.m

NSArray *const mFooKeys = [[NSArray alloc] initWithObjects: 
                                   @"Foo", @"Bar", @"Baz", nil];
NSArray *const mFooObjects = [[NSArray alloc] initWithObjects: 
                                   @"1", @"2", @"3", nil];
NSDictionary *const mFooDictionary = [[NSDictionary alloc] dictionaryWithObjects:mFooObjects 
                                                                         forKeys:mFooKeys]; 
Run Code Online (Sandbox Code Playgroud)

我是以dealloc发布的,一切都很好,还是有更多的东西?这个问题比一个"有问题"的问题更为谨慎,但我觉得如果没有意识到这一点,我真的可能会把它搞得一团糟.

release constants objective-c nsdictionary

7
推荐指数
1
解决办法
1万
查看次数

标签 统计

constants ×1

nsdictionary ×1

objective-c ×1

release ×1