1) When using private global variables, start them with underscores and put them in the interface portion of the .m file like so:
@interface MyViewController (){
NSArray *_tableData;
NSNumberFormatter *_numberFormat;
}
2) Only use @properties for global public variables and/or interface elements.
3) Synthesize the global publics and call them by name.
4) Call your interface elements with self.labelTitle NOT _labelTitle.
The main reason I use these variable naming conventions is because I can easily look at a variable and know what it's used for and its scope, but mainly it's a work around for the bug in XCode where you try and refactor -> rename a variable across the project and it doesn't work in certain circumstances outside of this convention.
I refactor my variable names A LOT and this system alleviated a lot of the problems for me.
Other Quick Tips:
- Use storyboard for everything that you possibly can, this alleviates the issues with code deprecation in new versions and it shrinks your total code base down significantly.
- Name your controllers VCMyName (view controller), NCMyName (nav controller), TVMyName (tableview controller), etc. This is better than Apple's standard (MyNameViewController) because tacking on the full name at the end is often cut off due to being too long in a lot of interfaces. Interface builder interprets the recommended naming convention correctly, calling the views "My Name".
- Learn and use Core Data, NOT your own make-shift SQLite querying system and create a helper unit for accessing data in one or two lines of code.
- Do not put all of your shared app code in AppDelegate, that's not really what it's for, instead create an AppController unit and use the singleton pattern to access it in your views as needed.
- Do follow Apple's convention of passing data forward to the next view controller and using delegates to handle returning data. This is much cleaner than storing globally accessible data somewhere.
- Create a Constants.h (h file only) for your project where you can store contants used across your project, like standardized row heights, etc. There should be nothing but #define in this file.
- Store login data in the key chain, that way it's more secure and if they delete the app and reinstall it completely, it's still there and you don't have to bug them with login requests.
- Store custom user settings for your app in NSUserDefaults, this takes them out of your DB so that if you have migration/other issues this data (which is possibly the only data you can't reload from scratch in your app) isn't affected.
- Pull requests from core data into dictionaries if you're passing them to a view, this keeps your core data entities out of your views and there's also a performance benefit.
- Follow Apple's Cocoa conventions for variable and function names. When in doubt, always see if Apple has a convention for it.
These are just off the top of my head. Of course, some people may disagree with what I wrote but these habits worked for me when I was getting started.