電話番号を受け取り、その電話番号が NSMutableDictionary にあるかどうかに基づいて BOOL を返すメソッドがあります。
これが辞書の構造です
キー値
携帯電話 1234567890
職場の電話 2345678910
自宅電話 4252433718
その電話番号が辞書にあるかどうかを確認するにはどうすればよいですか?
doesContain を試しましたが、数値が辞書にある場合でも常に NO が返されます。
電話番号を受け取り、その電話番号が NSMutableDictionary にあるかどうかに基づいて BOOL を返すメソッドがあります。
これが辞書の構造です
キー値
携帯電話 1234567890
職場の電話 2345678910
自宅電話 4252433718
その電話番号が辞書にあるかどうかを確認するにはどうすればよいですか?
doesContain を試しましたが、数値が辞書にある場合でも常に NO が返されます。
これでうまくいくはずです。
- (BOOL) hasNumber:(NSString *) phoneNumber
{
return [[phoneNumbers allValues] containsObject:phoneNumber];
}
NSNumber *object = [NSNumber numberWithInt:1234567890];
if ([dictionary allKeysForObject:object] count] > 0) {
NSLog(@"The number is in dictionary.");
} else {
NSLog(@"The number is not there in dictionary.");
}
これをチェックしてください..これがあなたが望むものかどうかわかりません
NSDictionary *dictionary = @{@"workhome":@(123123),@"homephone":@(456456)};
if (dictionary[@"workhome"] != nil)
{
//the key "workhome" has something
}
if ([[dictionary allValues] containsObject:@(123123)])
{
//the user has this number
NSArray *key = [dictionary allKeysForObject:@(123123)];
if (key.count > 0)
{
//now you have all keys for this object.
}
}