LoginSignup
3
3

More than 5 years have passed since last update.

Null passed to a callee that requires a non-null argumentエラーとは

Posted at

ちょっとだけ古いコードを触っていたらこんな警告に遭遇しました。

Null passed to a callee that requires a non-null argument NSMutableDictionary

実装的にはこんなかんじです。

NSMutableDictionary * xParams = [NSMutableDictionary dictionaryWithObjectsAndKeys:nil];

こんなかんじにしてみても同様です。

NSMutableDictionary * xParams = [NSMutableDictionary dictionaryWithObjectsAndKeys:nil, nil];

option+クリックでdictionaryWithObjectsAndKeysを見てみるとこんなかんじ。
スクリーンショット 2016-02-21 14.56.12.png

まだよくわからないので入力補完を見てみます。
スクリーンショット 2016-02-21 15.03.52.png

ここで「nonnull」という単語が出てきました。
nonnull、及びnullableについてはSwift Blogに詳しく書かれています。
簡単に言うとnonnullはnil, nullを許容しないものであり、nil, nullを渡した場合は今回のように警告が表示されるということのようです。
なので今回の警告が出た場合はnil, nullではない引数を渡す必要があります。

今回私の場合は引数に渡すものがない(nilを詰めることになってしまう)実装になっていたので、おとなしく普通の初期化を行います。

NSMutableDictionary * xParams = [NSMutableDictionary dictionary];

これで警告が出なくなりました。

3
3
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
3
3