2013-05-14 33 views
0

我有一個方法返回其參數中的某些值。這些值是具有KeyValues的NSDictionaries。如何使用鍵值複製NSDictionary

我想知道如何製作這些包含keyvalues的NSDictionaries的副本。

目前這是我想要做的。

//.h

NSMutableDictionary *tempDic; 

@property (strong, nonatomic) NSDictionary *tempDic; 

//.m

@synthesize tempDic; 


- (void)reciverMethod:(NSDictionary *)myDictionary { 

// I would like to get my method specific variable **myDictionary** and copy it into my global dictionary value tempDic like so 

tempDic = [myDictionary mutableCopy]; // this dosnt work 

} 

的東西behing myDictionary可能有幾個鍵值,您可以訪問使用

myDictionary.firstvalue 
myDictionary.secondvalue 
myDictionary.thirdvalue 

但是當我嘗試使用tempDic這些鍵都不可用。

即 tempDic.firstvalue tempDic.secondvalue tempDic.thirdvalue

dosnt工作...

任何幫助,將不勝感激。

+0

爲什麼你有一個全局名爲'tempDic'和一個名爲'tempDic'的屬性?這很混亂。 – rmaddy 2013-05-14 02:37:02

回答

1

1)中刪除此,NSMutableDictionary *tempDic;

具有這就夠了,

@property (strong, nonatomic) NSDictionary *tempDic; 

由於tempDic目的是強,非原子

- (void)reciverMethod:(NSDictionary)myDictionary { 
self.tempDic = myDictionary; 
} 

EDIT 1:

id value1 = [self.tempDic objectForKey:@"firstvalue"]; 
id value2 = [self.tempDic objectForKey:@"secondvalue"]; 
id value3 = [self.tempDic objectForKey:@"thirdvalue"]; 
+0

爲什麼你需要該字典的副本? – 2013-05-14 02:38:27

+0

因爲我想在另一個方法中使用它的值,所以我試圖將它傳遞給一個全局可訪問的變量。 – HurkNburkS 2013-05-14 02:40:37

+0

當我嘗試訪問鍵時出現此錯誤 **在'NSMutableDictionary *'類型的對象上找不到屬性'firstvalue',並且在我註銷myDictionary時出現此錯誤 – HurkNburkS 2013-05-14 02:41:25

相關問題