I've recently started learning Swift and SwiftUI for iOS development and I completely understand how to run my apps for testing using XCode. You just click the play button with whatever simulator device is selected. However, I really don't like using XCode. I want to use VSCode for my development. Looking online I can find very complicated tutorials on how to build my project for release on the App store or "Ad-Hoc" from the terminal. But, I don't think this is what I need. I'm wondering if there is a way to build and run my app from the terminal on to a simulator or personal device (connected with USB)? I understand I can just have XCode open on the side and run it from there while developing from VSCode, but, my computer is kind of old and having both those apps open makes my fans go crazy.
-
You can use the `xcodebuild` command to build from the terminal. – Andrew Dec 22 '22 at 07:41
-
I understand this, how do I build in the same way XCode does and then run on a simulator all from the terminal? – Ammar Ahmed Dec 22 '22 at 07:46
1 Answers
You can follow this guide on how to build your project using xcodebuild
.
Assuming you are in the directory with the .xcodeproj file, the command will look something like this:
xcodebuild -destination "platform=iOS Simulator,name=iPhone 14 Pro Max,OS=16.0" -scheme YourScheme SYMROOT="./build" build
Of course, you can choose any simulator you like. You can find a list of the simulators by doing xcrun simctl list
.
The built app will be located in a folder called build/Debug-iphonesimulator, or build/Release-iphonesimulator, depending on your default configuration. The configuration can be set by the -configuration
option.
Now you can launch the simulator. Here is a guide for that. Basically, you just specify the UUID of the simulator (again you can find this using xcrun simctl list
), and then launch Simulator.app. Example:
xcrun simctl boot 8F9690AC-FCDE-4913-9BD2-E54B3CC9F6C1
open /Applications/Xcode.app/Contents/Developer/Applications/Simulator.app/
To install the built app, you also need the UUID (see also this answer)
xcrun simctl install 8F9690AC-FCDE-4913-9BD2-E54B3CC9F6C1 build/Debug-iphonesimulator/YourApp.app
Finally, you launch your app by specifying the UUID of simulator, and the bundle ID of your app (source)
xcrun simctl launch 8F9690AC-FCDE-4913-9BD2-E54B3CC9F6C1 com.mydomain.YourAppBundleId

- 213,210
- 22
- 193
- 313
-
Thank you for the answer, I was actually just able to figure out how to do the same thing on my own. Do you know how to run the app on personal device connected by USB? I was able to find the UUID of the device with `xcrun xctrace list devices` but providing that UUID throws an error on install. – Ammar Ahmed Dec 22 '22 at 08:21
-
@AmmarAhmed Are you using `xcrun simctl` to install on a real device? That obviously won't work "simctl" stands for "*simulator* control". Have you come across [this post](https://stackoverflow.com/q/14535392/5133585) in your research? That could be a starting point. – Sweeper Dec 22 '22 at 08:27