SimulatorKit is a framework that wraps CoreSimulator
and simctl
to offer programmatic access to the Simulator app bundled with Xcode.
- macOS 11
- Swift 5.3
- Xcode 12
The preferred way of installing SimulatorKit is via the Swift Package Manager.
- In Xcode, open your project and navigate to File → Swift Packages → Add Package Dependency...
- Paste the repository URL (
https://github.com/vmanot/SimulatorKit
) and click Next. - For Rules, select Branch (with branch set to
master
). - Click Finish.
The goal of this framework is to provide a safe and idiomatic way to control the Simulator app.
Almost all functions on SimulatorDevice
are synchronous, blocking and throwing.
import SimulatorKit
print(try! SimulatorDevice.all())
import SimulatorKit
let iphoneSimulator = try SimulatorDevice.all().first(where: { $0.name.contains("iPhone") })!
try iphoneSimulator.boot()
import SimulatorKit
let iphoneSimulator = try SimulatorDevice.all().first(where: { $0.name.contains("iPhone") })!
let jpgDataOfScreenshot: Data = try iphoneSimulator.screenshot()