Xcode is an IDE used by iPhone developer or iPad app developer to do coding or developing iOS apps.
Xcode has many small and highly useful features which sometimes we are not aware of or it may happen that we may not be using those features at its optimum level in order to ease our iOS application development. For example : comments tag, code snippets, PO command and many more…
Here in this tutorial we will see 6 such useful features of Xcode which we can use during app development.
This tag is used for reminding yourself of things that you need to fix back again at some later stage of iOS app programming.
This tag is used for reminding yourself of things that you need to get back to at some point. Generally it is found at the top of the source file within the main comment block to remind us of features that need to update or add. Here you can see that.
It is used when you want to differentiate code into two category. One is for experiment and another is actual. For example.
If we change 0(zero) to 1(one). Than warning is automatically removed as shown below.
This technique will help you to ensure that you never release codes that includes / excludes code that shouldn’t / should be there.
This command is useful at debug time. In normal scenario, to print the value of a variable we have to move mouse pointer there and click on it and select print description print value of it. This is sometimes not programming friendly. With po command, this can be done easily and quickly. Lets see one example of it.
In this example, I have created one string named str and have set a value to it. Now to print that value without moving cursor over there, we just have to write “po variable name” in output window and then press Enter. As shown below, you will get value stored inside variable.
5. Code snippets
As a developer I observe that complex applications always need a well formatted code. So it is easy for other iOS developer to understand the code. So for this we will have to organize code in a standard format. But to organize code of larger applications, it will take some time. Xcode provides a functionality called snippets library. With the use of it we can organize code easily.
Xcode provides Code Snippets Library section where you can find all default code snippets provided by it. We can also create our custom code snippets as per our need and can add it over here for future use. Here are some examples of using code snippets…
When we add new ViewController class. The default code is show as below.
I want to follow structure like all Memory related methods are first and view life cycle methods are last like below.
To reuse the same structure again and again we need add this code into snippets library. Now to add this code into snippets library, select text that you want to add like below,
Press and hold mouse left key than Drag it to code snippets library. After adding it to code snippets library, you will see a default name “My Code Snippet”. You can edit the name and also add description and shortcut key to it for your reference.
Lets see how we can use this newly created code snippet.
Now to use this newly created code snippet, Go back to Code Editor and just type “vlm”. You will find that Xcode will display an option for create code snippets with its title and summary as per shown below. Once you select it, you will get your defined structure with pragma.
It is also possible to highlight code snippet’s part which will be change after executing it. For example. Pragma mark name which is not common and can be changed as per requirement. For that we can use create code snippets with parameter as per below
Select this parameterised code and create code snippets with same process which we followed earlier. Now when you use this code snippets, You will see code with parameter as per below
Press Tab key, It will directly move you to that and change the name accordingly.
6. Find your File
To find file Quickly in a project press cmd + shift + o.
Open Quickly window will open. Write just name of your file that you are looking for and then press Enter. It will redirect you on that file.
These are the things that might be very useful in coding if you are iOS developer, so I thought to share it for your quick reference. Hope you will find this list useful, if there are any other useful features of Xcode, then we would love to hear from you on those features.
Reference article: Click Here
Keep Coding 🙂