iOS Simulator on steroids: Tips & Tricks
iOS Simulator is an integral part of any iOS development process. We just canāt ignore it. New Simulator from Xcode 9 brings a lot of useful tricks, which could make you even more productive. Finally, Apple recalled they have Simulator out there! Comparing to previous modest updates, this one seems like a big deal. š
So letās break this down and list all features I found in new iOS simulator (some tricks you can use in the old Simulators as well).
#1 Use Simulator in full-screen mode with Xcode
When you have 13" screen the full-screen mode for Xcode is a just life saver. Unfortunately, you couldnāt use Simulator with Xcode in the full-screen mode previously. Well now you can š
This feature is enabled by default starting from Xcode 9b3. So you donāt even need to do anything to make it work.
UPD: It turned out this feature is disabled by default for some people, but donāt worry, you can always enable it via Apple Internal
menu as I described further.
If you want to explore more secret features in new Simulator you should enable Apple hidden Internals
menu.
To do so you need to create an empty folder with name āAppleInternalā in the root directory. Just run this command below and restart Simulator:
sudo mkdir /AppleInternal
The new menu item should show up. āļø
Note:
Iāve tested this approach on Simulator from Xcode 9b3. If you donāt have it, please download latest Xcode here.
#2 Open multiple Simulators at once
Do you remember the frustration of testing your app on different simulators? Previously you were forced to open only one Simulator instance at the time. There were many āhacksā how to open multiple instances of iOS simulator in an older version of Xcode. But finally, with Xcode 9 this feature is available out of the box.
#3 Resize Simulator just like a regular window
Before Xcode 9 we had āScale optionsā only to adjust simulatorās window size. Now Apple finally made resizing of the Simulatorās window available. Itās useful little detail which can help you organize workspace efficiently if you have multiple simulators opened.
#4 Record video of Simulator
In the official āWhatās newā document for Xcode 9, Apple claims that now you can record a video of simulatorās screen. Itās not completely true. You can do it even in the older versions with simctl
. I didnāt find any evidence you can enable video recording from the interface though (except for built-in screen recording in iOS 11).
For getting your video file, execute the following command:
xcrun simctl io booted recordVideo --type=mp4 <PATH TO VIDEO FILE>
booted
ā means, that simctl
selects currently booted Simulator. In case you have more than one booted Simulator, simctl
selects currently active instance.
#5 Share files to Simulator right from Finder
Now Simulator has Finder extension which allows you to share files directly from the Finderās window.
You can do something similar with image/video files using the simctl
command below:
xcrun simctl addmedia booted <PATH TO MEDIA FILE>
Itās nice to have such abilities. However, drag&drop file to the Simulatorās window seems much faster for me.
#6 Open URLs on Simulator
This one comes with simctl
as well. So you can open custom URL schemes on older Simulators too.
Execute the command below with whatever URL you need:
xcrun simctl openurl booted <URL>
For the list of all Appleās URL schemes please check out documentation.
#7 Quickly find appās container folder
One more command from simctl
. You can get appās container on the file system with a single command. You just need to know appās bundle identifier and execute the command below:
xcrun simctl get_app_container booted <APP'S BUNDLE ID>
Or you can make it even faster by opening destination folder in Finder with the open
command:
open `xcrun simctl get_app_container booted <APP'S BUNDLE ID>` -a Finder
#8 Launch your app in Simulator with command line args
With simctl
you can also launch your app from terminal and pass some command line arguments there (you can even setup some environment variables). It can be helpful if you want to add some hidden debug-only behaviour to your app.
The command below help you with that:
xcrun simctl launch --console booted <BUNDLE ID> <YOUR ARGUMENTS>
You can get these command line arguments from CommandLine.arguments
(here is the link to documentation).
#9 Get full application info with Bundle ID
Sometimes itās useful to find out where your app file or temporary data located on the file system. If you need more comprehensive information than simctl get_app_container
can give. simctl
also has this nice little tool called appinfo
which will show you some information in the following format:
{
ApplicationType = User;
Bundle = <PATH TO APP FILE>;
BundleContainer = <PATH TO FOLDER WITH APP FILE>;
CFBundleDisplayName = TestiOSApp;
CFBundleExecutable = TestiOSApp;
CFBundleIdentifier = "com.ahmed.app.TestiOSApp";
CFBundleName = TestiOSApp;
CFBundleVersion = 1;
DataContainer = <PATH TO YOUR DATA>;
GroupContainers = {
};
Path = <PATH TO APP FILE>;
SBAppTags = (
);
}
Execute command below and explore the output:
xcrun simctl appinfo booted <BUNDLE ID>
One last thingā¦
iOS Simulator is a very powerful tool which can speed up your development process a lot. But only if you know all little details and tricks. And obviously, as a good engineer, you have to know your tools.
Here at Flawless, iOS Simulator is extremely important for us. Our product is an iOS Simulator plugin which allows engineers to inspect any design on top of implementation right inside Simulator. So I canāt even tell you how happy Iām with this new Xcode 9 and Simulator release. Canāt wait for the public version! So we can implement more useful features to keep a visual quality of iOS apps in a good shape.
Also, if I missed something important feel free to add your tricks in the comments below. I believe it will be really useful to have more tricks in a single place š