Xcode Simulator App Advanced
In this tutorial, you’ll learn about Xcode Simulator’s advanced features to improve your daily development experience. By Vidhur Voora.
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress, bookmark, personalise your learner profile and more!
Create accountAlready a member of Kodeco? Sign in
Contents
Xcode Simulator App Advanced
30 mins
- Getting Started
- What Is a Simulator?
- Running App on a Device vs. a Simulator
- Computing Performance
- Display
- Hardware Limitations
- Framework Limitations
- Organizing Simulators Using Xcode
- Running Older Runtimes
- Creating Simulators From the Simulator Menu
- Comparing Simulator Size Options
- Physical Size
- Point Accurate
- Pixel Accurate
- Fit Screen
- Slow Animations
- Dark Mode
- Simulating Push Notifications
- Zooming In and Out
- Simulating a Location
- Sharing Locations From the Maps App
- Simulating Shake Gesture
- Simulating a Memory Warning
- Organizing Simulators Using the Command Line
- Creating Simulator From the Command Line
- Taking Screenshots
- Recording Video
- Customizing the Status Bar
- Debugging and Diagnosing
- Automating Using a Bash Script
- Implementing Launch
- Launching RayWonders in a Different Locale
- Where to Go From Here?
Implementing Launch
In launch
, replace #TODO
with the following:
#1
BUNDLE_ID="$1"
LOCALE="$2"
LANGUAGE="$3"
CLONE_NAME="$LOCALE"
#2
SIMULATOR_ID=$(get_id_of_simulator)
if [ -z "$SIMULATOR_ID" ]; then
echo "No device matching the name: $SIMULATOR_NAME"
return
fi
echo "Simulator id: $SIMULATOR_ID"
echo "Bundle id: $BUNDLE_ID"
echo "Locale: $LOCALE"
#3
SIMULATOR_STATUS=$(get_status_of_simulator)
echo "Simulator Status: $SIMULATOR_STATUS"
if [ "$SIMULATOR_STATUS" = "Booted" ]; then
echo "Making sure the device is shutdown first..."
xcrun simctl shutdown "$SIMULATOR_NAME"
fi
#4
echo "Cloning the device with name $LOCALE..."
xcrun simctl clone "$SIMULATOR_NAME" "$CLONE_NAME"
#5
echo "Booting device..."
xcrun simctl boot "$SIMULATOR_NAME"
xcrun simctl boot "$CLONE_NAME"
#6
echo "Launching app..."
xcrun simctl launch "$SIMULATOR_NAME" "$BUNDLE_ID"
#7
xcrun simctl launch "$CLONE_NAME" "$BUNDLE_ID" -AppleLocale "$LOCALE" \
-AppleLanguages "($LANGUAGE)"
Save the file. Here’s what this does, step by step. It:
- Gives additional parameters to
launch
, including the bundle ID of the application, the locale and the language to launch your app in. It declares a local variableCLONE_NAME
, which is the name of the cloned device. In this case, the name of the cloned device is the locale you specify; - Fetches the simulator’s ID by calling
get_id_of_simulator
. Then, it stores the result inSIMULATOR_ID
. If there is no matching simulator, it exits the program; - Fetches the simulator’s status by calling
get_status_of_simulator
. If the status isBooted
, it runs theshutdown
command to shut it down. To be cloned, a device must be shut down; - Clones the simulator using the
clone
command; - Boots both the original simulator and the cloned simulator using the
boot
command; - Launches the app on the original simulator using the
launch
command; - Launches the app using the
launch
command on the cloned simulator. It specifies the locale and language for the app to launch in.
Launching RayWonders in a Different Locale
Open Terminal, and run the following:
./sim_utility.sh launch Demo com.raywenderlich.RayWonders hi_IN hi
RayWonders launches in Hindi on a cloned simulator with the name hi_IN.
No more going to the settings and switching the device language to test your app. You can now see your app in multiple languages simultaneously. Great job!
xcrun simctl list | grep Demo
in the terminal. Delete any duplicate simulators and try again.
RayWonders also supports a few other languages. Run the following:
./sim_utility.sh launch Demo com.raywenderlich.RayWonders ja_Jp ja
RayWonders now launches in Japanese on a new simulator.
As a fun challenge, implement two more commands in the sim_utility script.
- Cleanup: This deletes a simulator given a simulator name.
- Help: This prints a menu of all the commands supported by the script.
You’ll find the final version of the script with all these options implemented in the Scripts folder in the downloaded materials.
Where to Go From Here?
Download the project by clicking the Download Materials button at the top or bottom of this page.
In this tutorial, you’ve learned tons of useful simulator and command-line options. To learn more, please check out these WWDC videos:
I hope you’ve enjoyed this tutorial. If you have any questions or comments, please join the forum discussion below.