2011-04-20 127 views
1

我有一個數組和字典,我想運行一些for循環來查看數組中的元素是否與字典中的每個鍵相等。以編程方式訪問字典鍵

有沒有辦法使用objective-c來做到這一點?

+0

你能提供你的數組和字典的樣本嗎? – 2011-04-20 18:23:43

+0

可以將數組中的對象與字典中的對象進行比較,是的。你試過什麼了? – 2011-04-20 18:31:26

回答

1
NSMutableSet *intersection = [[NSMutableSet alloc] init]; 
[intersection addObjectsFromArray:array]; 
[intersection intersectSet:[NSSet setWithArray:[dictionary allKeys]]]; 

intersection包含一組都存在在你的字典鍵和您的陣列中的對象。