Here are my top 5 tips and tricks for using Xcode! This is a script for a YouTube video I made which is right here!
If you have any tips, then please let me know in the comments cause I would love for them to be shared.
1. Build and Run Shortcuts
First off make use of the short cuts for building and running the app. These are actions you'll do a lot
Command + b= build
Command + r= run
These will save you time in the long run cause your hands are already on the keyboard and don't have to go click the Run button on the toolbar.
If you use the canvas, then make sure to jot down the shortcut to restart the live preview. The canvas will stop it's updating when adjusting anything not in the View it self, so if you add a variable or an environment object, you'll need to restart it. The shortcut is
Command + Option + p
So these three shortcuts are probably my most used short cuts.
The next most used shortcuts are in my next point.
2. Keep the file formatted
How many times do you go back into your code and look for a specific line or are just reading a section to understand what's happening? I know I do it all the time. Having a file with the right indention and is easy to follow cause the formatting is the same makes the world of difference.
Xcode has a way to format a section of your code.
Select the part you want to format and then press
Control + i
To do this to a whole file, select all then
control + i.
Command + a →
Control + i
Another reason to format your file is to easily know if something syntax wise isn't working. Sometimes this is faster than waiting till build time to find the error.
I just talked about keeping the file formatted correctly to help reading a file, but let's shift to navigating your file. Maybe I know exactly where I want to go, well that can be done pretty easily.
My 3rd topic is how to navigating your file like a pro.
3. Navigate your file like a pro
Utilize the drop down menu on the file name to navigate your file. What gets populated there?
- Declaration of properties
- Declaration of functions
- Comments that are MARKED
- Comments that are TODOs
You can click on any of these items and immediately be taken to that item. It's useful to get exactly where you need to be and also get a quick glance of what exactly is happening in a specific file.
Number 4 and 5 are how to make your code a bit better with a bit more work on your end.
4. The Add Documentation feature
Sometimes you can
Option + Click on a property name and get information about it. Especially when it's a class or function provided by Apple. Well, you can also do this for your code!
Command + click on the class, struct, or method and choose add documentation. You'll then be given a template to fill in! The best part is if you do this on a method or function that requires a property then it also gives those as well.
Let's see this in action by checking out OSCHelper. In here you can see at
selectProgrammingObject there isn't any documentation about what this does or when to use it, so I'm going to change that.
- Command click on the funciton name
- Choose Add Documentation
- Fill in the documentation
Now, when I option click on the name, I get the summary and what parameters are needed.
Tip number 5 is another option inside that menu and it's the rename feature.
5. The Rename feature
I'm sure we've all been there when a variable is declared, but then the name doesn't fit what you are using it for but then it's been used in 8 million different places. Well that's where the Rename feature comes in handy.
Command + click on a property name gives some options no matter where you are. It will also go through the project and completely rename all instances of that property, method, or function.
It's a very useful tool that saves me a lot of time and headache.
Hopefully these 5 tips help you out in your app development! If you found these tips useful make sure to hit the like button and drop a comment with some tips I missed! Thanks for watching!
If you want to chat with me and point out some tips and tricks, you can watch me work on iOS apps on Tuesday, Thursday, and Friday mornings at twitch.tv/maeganwilson_ Make sure to drop by and say hi!
Top comments (4)
Short and sweet!