我從服務器使用NSURLConnection檢索pList,由我寫的一些php生成的。我的Plist在根級別包含幾個數組。這些數組包含服務器NSDictionyObjects。一旦我檢索到pList,我使用NSPropertyLitSerialization將數據序列化成一個NSDictionary。NSDictionary vs自定義對象的性能
現在,一旦我有了這個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傳遞我的價值觀周圍的應用程序,它工作正常。我覺得編寫代碼和使用值對象更好的做法會更容易,但是現在使用值對象的Im感覺像是在浪費更多的內存。感覺就像我將這些沉重的物體放在哪裏,像以前一樣,我只是在需要時從字典中獲取值。