我希望能够像这篇文章中所做的那样实现一些类似的功能:Constants in Objective-C
但是,我想构建一个NSDictionary。
如果我做了这样的事情:
constants.h
extern NSArray *const mFooKeys;
extern NSArray *const mFooObjects;
extern NSDictionary *const mFooDictionary;
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];
我需要在dealloc中释放对象,这样就可以了吗?还是说还有其他需要注意的地方?这个问题更多是谨慎提问而不是“出了什么问题”的提问,但我感觉如果没有意识到可能会弄糟这个问题。