Join Steven Lipton for an in-depth discussion in this video Use the Xcode 9 simulators, part of iOS Development Tips Weekly.
- [Instructor] One very welcome change to Xcode 9 is the revamped simulators. Let's look at some of the new features and issues with the new simulators. I like to preload my simulators before running apps in Xcode. You'll need Xcode running and showing in the dock. Right-click Xcode in the dock, go to Open Developer Tool, and Simulator. I have an iPhone X launched. Yours may be different. I usually add this to my dock with Keep in Dock for easy prelaunch. You can add more devices by going to Hardware, Device, and select a device group.
I'll add an iPad Pro 9.7 inch. Try again with an iPhone SE. You can also add an Apple TV or Apple Watch to the simulator the same way. Click and hold on the dark bezel of the iPad. Drag, and the tablet drags to a position wherever you want. Click on a corner of the bezel and you can then scale it to exactly the size you want.
Slide and arrange everything to what works for you. You can also automatically scale by going to Window, Scale, and picking which ones are available. I'll pick Actual Size for the SE. Once you're done with the simulators you can clean them off your screen. There's two ways to do this: you can shut off the bezel in Window, Show Device Bezels, and shut that off. You'll get the traditional-looking simulators. From here you can close the simulator.
I'll close the SE that way. Then put back the bezels. Alternatively, you can select the simulator and use command w from the keyboard. I'm going to try that on the iPhone X. And hit command w, and it disappears. Now here's the cool thing about the bezels: the buttons work. Select the Settings button on the iPad. Now click the Home button, and it works like a Home button. While you might have command L memorized to lock your phone, you can also click the Lock button and click Home to open.
The volume buttons also work. You use the simulator the same way a user would use a real device. The one exception is the iPhone X, where the swipe from the bottom as of this writing isn't working. You'll still have to use command shift h for this for home. You also get Siri; hold down the Home button, Siri appears. What's the airspeed velocity of an unladen swallow? Go ahead and hit Home. With two simulators up you can look at the same app on different devices.
Open up the iPhone 8 Plus, and now click into Xcode. I have set in Xcode a label on a storyboard. I've varied the font size depending on the size class. And I'm going to set it for iPhone 8 Plus. I'll build and run, and it runs on my iPhone. You can run this on the iPad without switching simulators. Open the Products folder on the bottom of the navigator view and you'll find the SimulatorDemo.app down there.
Click on the simulators, and now drag SimulatorDemo.app to the iPad and release. It'll load that app; you can click it and run it. This app is set for simulator use because we built it and ran it on the iPhone first. If you're switching between a live phone and simulators remember to rebuild and run on the simulator after running on the phone. Copying a phone app to a simulator won't work. You're running this app on both devices now.
The last feature that has been there for a while but one you'll want to use frequently is Hardware, Erase All Contents and Settings. Simulators are memory hogs, and they can eat your hard drive and gigabytes. When you've finished a project you may want to clean them this way. You've learned how to run an app on two simulators and how to use the new bezel feature and the buttons. For more on the simulator check out the Help feature.