LoginSignup
11
11

More than 5 years have passed since last update.

NSDictionaryのTips

Last updated at Posted at 2014-02-10

たまに忘れるのでメモ、どんどん増やすかも

キー(添字)が存在するか確認する

allKeysメソッドを使ってキーの配列を取得し、そのキー配列に対象となるオブジェクト(検索するキー)があるかどうか比較するだけ

NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:
                            @"value1", @"key1",
                            @"value2", @"key2",
                            @"value3", @"key3",
                            nil];
if (dictionary[@"key1"]) {
    // 存在する場合の処理
}
11
11
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
11
11