Some useful command for Apple developers

Being developer for iOS/macOS platforms sometime can be a tricky task, and engineer has to remember a lot of different commands and keep in mind how to use some tools. Here comes the short-list. As an example:
sudo xcode-select -r

This command resets your Xcode to the default version. This might be useful when you were needed to have 2 IDEs simultaneously located in different places on your disk, so the command above always helps to get back. For instance, I was not able to run xcrun simctl erase all until I’ve reset the version.

Next, but not least.

If you’re using command-line very often, saying for CI/CD setup, you might be faced with the issue when the xcodebuild is not working as intended. Here the next command that can help:

sudo xcodebuild -license

Yeah, something might not work in case you’ve not accepted the license agreement. Entering the given command, you’ll see it. Just follow the instructions and you’ll resolve the issue.

Let’s get back to almighty xcrun command. Now, in case you ever tried to figure out how to capture video from the simulator, but failed in that, here is the resolution:

xcrun simctl io booted recordVideo filename.mp4

As you can guess, the command above starts to capture video to the file you’ve specified until you press Ctrl+C

Little bit more advanced version of this command looks like this:

xcrun simctl io booted recordVideo --codec=h264 --mask=black --force appVideo.mov

Also, you often may be needed to import signing certificate and private key as well. This can be done in following way:

security import cert_name.p12 -k ~/Library/Keychains/login.keychain

security import private_key.pem -k ~/Library/Keychains/login.keychain

By specifying very specific debug flags in Xcode, you can enable execution time profiling for the functions in Swift:

OTHER_SWIFT_FLAGS = "$(inherited) -D COCOAPODS -Xfrontend -debug-time-function-bodies"

The full list of diagnostic options you could supply in Xcode, are listed in the reference page:

https://github.com/swiftlang/swift/blob/main/docs/CompilerPerformance.md#diagnostic-options