-1
我想在由其他類訪問的類使用一個NSDictionay(我認爲這是正確的方法),以將數據保存到:兩個多維陣列與對象
.H
@property (retain, nonatomic) NSArray *NameKey;
@property (retain, nonatomic) NSArray *DataFields;
@property (retain, nonatomic) NSDictionary *MDArray;
.M
@synthesize NameKey;
@synthesize DataFields;
@synthesize MDArray;
- (id) init
{
NameKey = [NSArray arrayWithObjects:@"DeviceName",nil];
DataFields = [NSArray arrayWithObjects:@"Serial", nil];
MDArray = [NSDictionary dictionaryWithObjects:DataFields forKeys:NameKey];
}
幾個問題:
這是設置NSDictionary的正確方法嗎?
如何添加/刪除/修改數據。假設名稱是唯一的
在此先感謝。
僅供參考 - 標準命名約定規定變量和方法名稱應使用小寫字母。只有類名以大寫字母開頭。 – rmaddy
另外,'@ synthesize'的使用在很大程度上是過時的。爲什麼你的字典命名爲「MDArray」而不是「mdDictionary」?你真的需要這兩個數組的屬性嗎?該數據將在字典中。 – rmaddy
爲什麼具有'NSArray'類型的屬性'nameKey'是一個單數形式?而且......爲什麼沒有人在發佈SO之前閱讀介紹? –