In this article, I am going to talk about some of the tricks and shortcuts that help me in Xcode. I hope they help you, too.
The original article is written in Turkish. Therefore some of screenshots may have Turkish words on it.
1. Searching using RegEx
I always love using RegEx while searching. It helps me find what I want easily. So, how do we use this feature?
- Select File Navigator from the menu to the left in Xcode.
- Switch the Text preference to Regular Expression.
- Now, you can search what you want using RegEx.
You can also make use of online websites, such as https://regex101.com, to improve your RegEx use and to check the validness of RegEx that you wrote.
2. Opening A Project from Terminal with Xcode
You can open Xcode projects using Terminal. If you run the xed. command in the main index of any Xcode project, it will open the project directly.
If it is a workspace project, it will automatically open the .xcworkspace file.
3. Viewing the Interface of Class and Struct Files
If you want to check quickly the parameters and methods used in the object, the following method can be useful for you.
- Open the Class or Struct file.
- Use the ⌘⌃↑ (Cmd+Ctrl+↑) shortcut.
- Xcode will automatically create the interface of the object.
4. Quick Access to the Methods and Variables in the Object
You can get access to any method or parameter in the object you want to find using the Jump Bar.
- Use the ⌃6 (Ctrl + 6) shortcut while in the Class or struct file.
- It will open the Jump Bar window for the list of methods and parameters in the object.
- You can choose the method or parameter you want to get access directly or you can filter the list by typing in order to get access faster.
5. Watching Variables while Debugging
You have the opportunity to watch the certain status of applications while debugging with the breakpoint feature of Xcode. So far so good, however, when you want to watch the change in the variable you want to monitor or to see which line causes the change, you can use the following method.
- Put breakpoint in the place where the variable you want to watch is created first.
- Right-click on the variable you want to watch in the Debug Area at the bottom-left when the running of code for the breakpoint is stopped after you run the project.
- Continue to run the program after choosing Watch “variable name”.
- Now, when there is any change in the variable you watch, Xcode will show you the line that causes the change.
6. Using the Assistant Editor More Effectively
I prefer using the Assistant Editor (Split Screen) while working on two files at the same time. If you also prefer working like this, you must have needed to change the file in the editor at some point. In order to change the file in the secondary editor, hold down the ⌥ (Option / Alt) button and click on the file you want to open from Project Navigator to the left. In addition to this method, there is also another way to do this.
- Go to Preferences window in Xcode.
- Go to Navigation tab from the top menu.
- Select “Uses Focused Editor” for the Navigation feature under the Navigation tab.
- Now, while using Assistant Editor, the file you select from the Project Navigator will open in wherever your cursor is.
7. Quick Access to Any File or Line in the Project
In order to access quickly to any file in the project, you can open the Quickly box by the ⌘⇧O (Cmd+Shift+O) shortcut and do a search. Therefore, you can access any file without wasting time. So far so good, however, when you want to go to a specific line inside the file you search for, you can use the following method.
- Open the Quickly box using the ⌘⇧O (Cmd+Shift+O) shortcut.
- Type the name of the file you want to access until it shows up on the list.
:linenumberto the end of the search in order to find the line you want to access. Example:
- When you click on the file you want to get access from the list on the screen, Xcode will take you to the respective line of the file.
BONUS: Quick Access to an Open File in Project Navigator
You got access to the file you searched for with the method above, but now, you want to see the file in Project Navigator. For this, you can use the following method.
- Use the ⌘⇧J (Cmd + Shift + J) shortcut while the file is open.
- You can see the relevant file in Project Navigator.
This is all I have compiled for this article. See you in the second part! If you liked this article, don’t forget to like and subscribe to me.