3
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Objective-cで意図的にクラッシュさせる

Posted at

意図的にクラッシュさせる(Objective-c)

通常Xcodeで実行すれば、ブレイクポイントを作成すれば、必要ないのだけど、
アプリがバックグラウンドにない状態の時に、URL schema(ディープリンク)などでアプリを起動させた時の挙動を確認したい時がありました。
この場合、Xcodeでの実行はできません。

考えた末、意図的にクラッシュするコードを埋め込み、そこまで到着しているか確認するというとこにたどり着きました。
以下のコードでクラッシュさせます。

assert( [@"a" isEqualToString:@"b"]);

assertの引数がTrueでなければ、クラッシュするようになりました。
こんな使い方もできます。

# variable_objがnilの場合はクラッシュさせる
assert(variable_obj != nil);

もっとスマートなデバッグ方法があれば教えてください・・

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?