2012年2月13日月曜日

Utilize Auto-Completion in Xcode


http://upload.wikimedia.org/wikipedia/en/0/0c/Xcode_icon.pngXcode has great code-completion (or auto-completion) and by utilizing this wisely we can save ourselves lots of trouble. A good thing to do at the beginning of every app development is to create an global.h file to hold all constants, strings, etc, and include this in all the classes where needed. Even though it might not feel necessary at the start of a small project, as new functionality is added the amount of constants, strings, etc, needed quickly grows and it becomes difficult to remember them all. By collecting them all in one place, we make configuration, updates and changes very easy to do.


My Global.h can look something like this:

// NSUserDefaults
#define kUDMusicState           @"MusicState"           // BOOL
#define kUDSoundState           @"SoundState"           // BOOL
#define kUDNrOfPlayers          @"NrOfPlayers"          // int
#define ...

// Notification Center
#define kNCFacebookLogin        @"FacebookDidLogin"
#define kNCFacebookLogout       @"FacebookDidLogout"
#define ...

// Images
#define kImageHelpGamePhone     @"helppageGame"        
#define kImageHelpGamePad       @"helppageGame~pad"
#define ...

Now, when somewhere in my code I need to access NSUserDefaults. I know that all my NSUserDefault keys start with kUD... so when I type kUD all the keys are presented to me and I can easily choose from the menu the one I need.
















Same when I need an images, simply typing kImage... and code-completion gives my a list of all my defined image names. No more going back to check what the filename was or looking for bugs that are caused by wrong spelling in the key string (maybe I'm the only one who get this kind of bug *_* )

If Xcode doesn't show the auto-completion list, try hitting ESC. If still no suggestion comes up, the needed file is not included or you're trying write something that doesn't belong there. On rare occasions the auto-completion systems fails to work properly but building the project should solve that.

If you have any good tip on how to make the most of Xcode, please let me know!
140 180 iOS

記載されている会社名、および商品名等は、各社の商標または登録商標です。

0 コメント:

コメントを投稿

Related Posts Plugin for WordPress, Blogger...