In the previous workshop you learned how to use the Assistant editor to connect the view’s objects in IB. In this workshop you learn how to Run the iOS Swift Variable app in the iPad Simulator.

Before you begin, I assume you’ve done the following:

To test the Swift Variable application in in the iSO Simulator, you have to select an iPhone or iPad simulator from the active scheme menu, then click the Run (aka Play) button.

xcode6-play-stop-scheme

Wait for Xcode to launch the application in the iOS simulator. This may take some time. Once the application’s view appear in the simulator, you will have to change it its size by selecting Window | Scale | 75% or 50%. Heres what the Swift Variable application’s view will look like on the iPad 2 Simulator scaled at 75%.

workshop8-fig1a
Figure 1: Portrait view of the app’s View

As you can see in Figure 1 above, the Text View doesn’t appear on the simulator’s screen. What give? Here’s the reason for this problem:

The Text View control is missing a layout constraint that’ll make it appear on screen.

Steps to Fix The Layout Constraint Problem

Now to fix the layout constraint problem, you’ll have to do the following.

1. Click the Stop button on Xcode’s Toolbar’s. This will terminate the app in the iOS Simulator.

2. Click the Main.storyboard file. Hold down the control key and click-drag the Text View right-see Figure 2A below. Release your mouse when the entire view is highlighted in blue.

workshop8-fig02a
Figure 2A

3. From the pop-up menu shown in Figure 2B, select Trailing Space to Container Margin. Xcode will add a constraint for the Text View and it will appear as a vertical line on the right side of the storyboard canvas. The blue arrow in Figure 2C shows where it is.

workshop8-fig02b workshop8-fig02c
Figure 2B Figure 2C

4. If you were to preview the layout in the Assistant editor, you will see no change after adding the constraint. You will have to run the app in the iPad Simulator again to see the effect of adding the constraint.

workshop8-fig03 workshop8-fig03b
Figure 3A: Portrait orientation Figure 3B: Landscape orientation

Figure 3A and 3B above shows what the iPad Simulator will look like in portrait and landscape orientation. Now, to put the iOS Simulator in landscape orientation, select Hardware | Rotate Left. To put it back in portrait orientation, select Hardware | Rotate Right.

When you run the app in the iOS Simulator, Xcode display an error message  in the Debugger window. The error is basically telling you that you’ve to many constraint for the Text View control. To make the error message go away, you have to delete the constraint indicated by the arrow in the image below. Just click the Text View then click the constraint to select it. Now, hit the “delete” key on your keyboard. Now, run the app again and you won’t see the error message.

workshop8-figh04

That’s it. Now you know to run the Swift Variable application in the iPad 2 Simulator. You also know how to fix the Text View constraint problems. Now is a good time as any to run the application in the iPhone 3 and 4 simulator to see what it look like.

Before you go, here are some handy, dandy Xcode and iOS Simulator keyboard shortcut keys, which you will be using a lot.

Xcode IDE Keyboard Shortcut keys iOS Simulator Keyboard Shortcut keys
(⌘ R) Run the app in the iOS Simulator
(⌘ .) Stop running the app in the iOS Simulator
(shift ⌘ K) This is the “Clean” command,
which delete various cache files that Xcode
creates during the build process.
(⌘ ←) Rotate the simulator left
(⌘ →) Rotate the simulator right
(⌘ K) Toggle Software Keyboard
(⌘ 1) scale the simulator to 100%
(⌘ 2) scale the simulator to 75%
(⌘ 3) scale the simulator to 50%
(⌘ Q) Shut down the iOS Simulator

Tags:

No responses yet

Leave a Reply

UIDocument Demystified: A Step-by-step Guide on Local and iCloud Document Storage

 

Archives