Chapter 7. Xcode 9 and Interface Builder

In this chapter, we are going to have a look at some of the updates to Xcode and Interface Builder. We will start with Xcode and some of the really exciting features that have been added to it since the previous version.

7.1 Changing Variable Names in the Current Scope

Problem

You want to quickly change the name of a variable in the local scope, for instance, inside the current function that you are in.

Solution

Follow these steps:

  1. In the function where you have defined your variable or constant, move the keyboard cursor over to the variable or constant name. Where in the name doesn’t matter.
  2. Simultaneously press the Cmd-Ctrl-E keys on your keyboard.
  3. The Xcode editor will then highlight the selected variable name in the entire scope of your function. If this variable or constant is defined outside the current function or scope, all instances where it is being used will now be highlighted.
  4. Start altering the variable or constant name by typing a new name or just editing the existing one.
  5. Once you are done, press the Enter key on your keyboard to finish the editing process.

Discussion

If you selected a variable name that is defined in the current function, changes that you make will not affect a variable of the same name that is outside this function’s scope. You can see the scope where editing takes place in Figure 7-1. Here I am editing the name of a locally defined constant inside a function called example(). Another constant ...

Get iOS 11 Swift Programming Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.