Getting the Most Out of Simulator
Show Apple's description.
Join us for a deep dive into the world of Simulator. Find out how Simulator works, discover features you might not know exist, and get a tour of the command-line interface to Simulator for automation. Learn about native GPU acceleration in Simulator via Metal, and how to optimize your Metal code to take advantage of it.
What’s a simulator?
- Apple simulators (iOS, watchOS, and tvOS) are completely separate user spaces that run on top of the macOS kernel.
- They have separate
launchd, separate daemons, separate darwin notifications, separate URL sessions, and separate mach bootstrap
- Same filesystem as macOS but separate
libSystemand up: built for iOS, watchOS, or tvOS Uses iOS, watchOS, or tvOS ABI built natively for x86 (not an emulator)
- Memory and CPU limits are not simulated (you get the memory and cpus of your Mac machine)
- Different core counts, different threading behaviors
- Application Sandbox is not enforced
- Simulates case-sensitive filesystem (most platforms are case-insensitive, but this adds a nice extra safety net)
- Thread Sanitizer supported (even on platforms that don’t support them natively)
The talk continues with different tips and tricks on what you can do in the simulator.
Simulator window size
Run new iOS simulators with old Xcode:
Share between simulator and machine
The most common way is just drag and drop, however you can also use the share sheet:
￼ You can then target a single simulator or to all the simulator at once.
Use the Simulator via Command Line
The talk then goes through an overview of the
xcrun simctl command line:
$ xcrun simctl listshows installed devices and their statuses
$ xcrun simctl create <name> <device type> <runtime>creates a new device
$ xcrun simctl create "Test Watch" "Apple Watch Series 4 - 44mm" watchOS6.0
$ xcrun simctl spawn <device> <command> <arguments>lets you launch and change the simulator behavior (logs, inject user defaults..)
$ xcrun simctl diagnosecaptures logs and states useful especially on CI when a test fails
$ xcrun simctl launch <device> <command> <arguments>launches the app
$ xcrun simctl launch --console-pty booted com.apple.example -MyDefaultKey YESlaunches the app, connect the logs to the terminal, writes the usersDefault value true for key “MyDefaultKey”
$ xcrun simctl boot
$ xcrun simctl shutdown
$ xcrun simctl deletedeletes a device
$ xcrun simctl delete unavailableremoves all simulators that are not available any longer (old Xcode installs)
The talk ends with an overview of Metal being available to the simulator and reasons why it is awesome, for us we will see all the places where we use it (a.k.a. UIKit) run smoothly in the simulator.
While cool, this might make things go well on the simulator, but lag on the real device (because now we can have better performance in the mac). Therefore always test on the real device when we have computation heavy tasks at hand.