Avatar ·

How to determine if an app is being built for simulator or real device in Swift

Hello everyone! I'm new to iOS development and I've run into this problem.\n\nMy app has functionality related to the camera and access to contacts. On a real device everything works fine, but when I run the project in the Xcode simulator (e.g., iPhone 15 Pro), the app crashes with an error because the simulator doesn't support the camera. I want to add a check in the code so that on the simulator it just shows a placeholder, and on a real device it opens the camera.\n\nI tried using `#if TARGET_OS_SIMULATOR`, but the compiler complains that it's an undefined identifier. Then I found `#if targetEnvironment(simulator)`, but I'm not sure if I'm using it correctly. My current code looks like this:\n\n```swift\nimport UIKit\n\nclass CameraViewController: UIViewController {\n override func