5 simple tips to make your app development faster and hope to give you some tips to be a better developer. Everyone can create an app nowadays, but not so many people can maintain a certain level of coding style and create source codes that can be reused in other projects.
1. Use code snippets
A code snippet is really really useful when you write thousand lines of source code daily and often write the same code over and over again. Wouldn’t it be cool if we had those code snippets for our iOS apps where you just type something and the whole 10-20 lines of code is inserted right into where you want it? I tell you, it wouldn’t be cool, it would be awesome or actually it is. I often have to write codes to present an UIAlertView for example or the delegate methods of NSFetchedResultsController, which doesn’t really change or you don’t really need to tweak it much, but it’s a lot of code to write (or to copy from one of your old projects). That’s when code snippets come in handy and Xcode supports it thank God.
Check out this tutorial about code snippets here.
2. Store each project in a separate repository
When it comes to creating a new project or app, make sure to have a separate .git repository to be able to manage your code better.
There are several benefits to use some kind of source control:
- You can share your code easier with your colleagues, designers or clients. Or even with your other Mac, personally I have a Mac Pro and a Macbook Pro, but most of the times I use my Mac Pro, so when I switch to my laptop, I just check out the branch that I was working on and I continue the work where I was before.
- You can/should create separate branches for each feature/bug, this way it is easier to track the progress of each feature/bug and develop them separately.
- See who messed up. If you are working in a team, you can easily see with Xcode’s built in Blame feature to see who created the method which makes the app crash now.
- Awesome backup solution. In case of anything happens to your Mac’s hard drive or your Mac got stolen, it can save you a lot of troubles and headaches when you have your new awesome app in a repository.
There are a lot more reasons, why you should keep your source code in a repository, I just wanted to highlight some of them.
3. Align UI elements with shortcuts
Lot of people probably don’t know this feature. It is pretty hidden by default, so you either learnt it from someone else or found out by yourself accidentally. For me the it was the last case. I was using Xcode’s Interface Builder when I pressed my keyboard somewhere, which showed some weird numbers and arrows on my app’s view. I tried to locate that button again and found it luckily. That awesome key is the “Alt” key (or Option) on your Mac. Just select an UI item that you want to put into the right place and press the Alt key. Voila, it will show you how far that button is located from the left side of the screen or from the other elements.
When I’m aligning my UI elements I always use this technique. select the element I want to align, press Alt than using the arrow keys on my keyboard I align it to the right place. Simple and quick.
4. Write tests
Writing test cases, makes your app development and bug tracking time a lot faster. For example when you are creating a registration feature for your app, you wouldn’t want to launch the app every time you make some adjustments to it, to see if that worked or not, especially if your registration screen needs 5-6 taps and have 2 fields to be filled out. All of that can be executed with a separate test case, and see if your modification actually does something.
5. Write clear, reusable code
Read the title again and follow. You can save a lot of time by just creating methods or classes that can be reused in another project. Try to create general methods that can be used in many cases, so you don’t have to rewrite it again. A best example for this is using categories. Categories are extensions of already existing classes, for example you want to have a method for the UITextField class, that let’s you decide if the textfield contains anything or left empty. (I know this can be done by saying “textfield.length > 0” but it looks better and easier to understand if we say “[textfield isEmpty]” which returns a boolean).
That’s all folks now. Hope you gained some new knowledge and ready to use it in your own projects.