Avatar ·

How to programmatically determine if an app is running in the iPhone simulator?

Hello everyone! I'm a beginner iOS developer and I've encountered a problem: I need one code to run in the simulator and another on a real device. For example, I want to use the camera only on a real iPhone, and in the simulator just show a placeholder. But how do I check this programmatically? I tried searching online, but I came across various macros and compilation flags. In Objective-C it looks like this: ```objectivec #if TARGET_IPHONE_SIMULATOR // code for simulator #else // code for real device #endif ``` But I'm writing in Swift, and I can't directly transfer this construct. I tried using `#if targetEnvironment(simulator)`, but Xcode complains that it's an invalid directive. Maybe I need to import or include something? Or is there