【发布时间】:2010-12-13 01:01:27
【问题描述】:
我正在使用 NSURLConnection 从服务器检索由我编写的一些 php 生成的 pList。我的 Plist 在根级别包含几个数组。这些数组包含服务器 NSDictionyObjects。检索 pList 后,我使用 NSPropertyLitSerialization 将数据序列化为 NSDictionary。
现在,一旦我有了这个 NSDictionary,我就会将值加载到我使用以下代码创建的自定义对象中。
NSMutableDictionary *newDict = [[NSMutableDictionary alloc]init];
//Create object array.
for (NSString *key in dict) {
NSArray *tempArr = [dict objectForKey:key];
NSMutableArray *gameObjectArray = [[NSMutableArray alloc]
initWithCapacity:tempArr.count];
for (NSDictionary *tempDict in tempArr) {
//Build Objects and add to array
GameObject *tempGame = [[GameObject alloc] initWithArr:tempDict];
//initWithArr initializes the values in the object using tempDict
[gameObjectArray addObject:tempGame];
[tempGame release];
}
[newDict setObject:gameObjectArray forKey:key];
[gameObjectArray release];
}
self.gameObjectsDict = newDict;
从现在开始,我将在整个应用程序中使用存储在 gameObjectsDict 中的值对象。适用于各种东西,包括渲染 UITableViews 和将数据传递给其他 viewControllers/views。
我的问题: 将我的 pList 中的所有这些值放入值对象中是否值得?
以前,我只是使用 NSDictionary 在应用程序中传递我的值,它运行良好。我觉得使用值对象会更容易编码和更好的实践,但现在我使用值对象如果感觉我在浪费更多内存。感觉就像我在传递这些充满数据的重物时,我只是在需要时从字典中获取值。
【问题讨论】:
标签: iphone memory object plist