Ios – What’s a reliable way to make an iOS app crash

iosiphoneobjective c

I want to test my app's crash reporting out in the field by deliberately having it crash when the user performs a particular action that a real user is unlikely to do accidentally.

But what's a good reliable way of making the app crash that doesn't create a warning at compile time?

Edit: Note that many seemingly obvious answers to this question result in exceptions that get caught by Cocoa and thus don't result in the app crashing.

Best Answer

in Objective-C use C directly to cause a bad access

strcpy(0, "bla");

Note: while this works on any system I know -- in a future version of the C runtime OR the compiler this might not lead to a crash anymore. see Is null pointer dereference undefined behavior in Objective-C?)

(in swift you would have to bridge to objC to do this)