Research, Dev, Share

Windows Phone 7 v.s iPhone Presentation in Barcampsaigon

Posted in C#, Iphone, Objective-C, Software Development, Windows Phone by Khang Vo on December 12, 2010
Windows Phone 7 and iPhone Presentation

Windows Phone 7 and iPhone Presentation

Here is my presentation with Nghia Dang on the topic comparing the differences between Windows Phone 7 and iPhone Development. I share it here for others who cannot come. Contact me (vodkhang@gmail.com) or Nghia (nghiadang@kms-technology.com) if you have any questions:

Kms-Technology

Property, Synthesize and Dealloc – Code Generation

Posted in Iphone, Objective-C, Software Development by Khang Vo on November 25, 2010

This is my new generation script, mainly copied from here with some improvements to meet my needs:

– Change the dealloc to [self.variable release] instead of [self.variable dealloc];
– Change the @outlet variable to check for the “UI” prefix rather than letting it put IBOutlet everywhere or I have to use 2 scripts at the same time.
– Add some of my own into the assign list

XCode Code Generation

The second one is not a perfect solution for IBOutlet but considering that it doesn’t harm much except let some annoying IBOutlet out.

Become Master of XCode (part 2)

Posted in Objective-C, Software Development by Khang Vo on September 27, 2010

I recommend you to have some few experience with XCode before trying to touch some of the techniques here, especially code generation because it may contain subtle bugs and if you are just a newbie, it is not easy to solve. You may also want to take a look at my first part: Become Master of XCode
Many of the techniques are learnt from “Becoming productive in XCode”

3/ Code Generation Scripting

The most common and boring problem that iPhone developers usually have is writing again and again: private instance variable, @property, @synthesize and then dealloc. It is not just boring but also easy to make mistake. Currently, I found that there is a useful way for developers to generate all @property, @synthesize and dealloc based on the instance variable.

Go into User Script, create your own group and script name:

Copy the script from Github (thanks to AllanCraig) and put into. Don’t forget your hot key to trigger the code generation. You may also need to configure the script a little bit to fit your own purpose and coding convention

4/ Code Template (Text Macros)

They have 2 main kinds of code templates: the built in text macros and your text macros:

a/ Default Text Macros:

Xcode already includes lots of text macros like: init, dealloc, fore (for each), fori (normal for loop over array). See a long list in XCode Completion Macros.

Here is the path for the built in Text Macros:

/Developer/Applications/Xcode.app/Contents/PlugIns/TextMacros.xctxtmacro/Content/Resources/

b/ Your own Text Macros:

You can put more Text Macros into Xcode by understanding and writing the Text Macros yourself. The file location for your Text Macros is: ~/Library/Application Support/Developer/Support/Xcode/Specifications

Here are some samples Text Macros that I will work through to get you the feeling of the Text Macros. I hope that after I exlain it, you can create your own.

{
  Identifier = objc.dealloc;
  BasedOn = objc;
  IsMenuItem = YES;
  Name = "Dealloc Method Definition";
  TextString = "- (void) dealloc$(BlockSeparator){\n\t<#!deallocations!#>
\n\t[super dealloc];\n}\n";
  CompletionPrefix = dealloc;
}

Identifier : the id of your method

BasedOn : the programming language of your macro. Here is objc

Name : a descriptive name

Text String: the text string will replace your Macros:

${BlockSeparator} :  the way you specify the spaces in your code, you can configure it through terminal and script

<#!deallocations!#> : a placeholder with the text deallocations.

[super dealloc]; : the text appears in your macros

5/ File and Project Templates

You can change your file and project templates, there is not much to say here. You have a built in project and file templates in:

/Developer/Platforms/iphoneOS.platform/Developer/Library/Xcode/Project Templates

/Developer/Platforms/iphoneOS.platform/Developer/Library/Xcode/File Templates

But you should create your own file and project templates in:

~/Library/Application Support/Developer/Shared/Xcode/Project Templates

~/Library/Application Support/Developer/Shared/Xcode/File Templates

You may want to copy some from the default templates and modify. The reason that you should put in your own folder is that if Xcode is upgraded, it will not delete your modification

Reference:

http://cocoawithlove.com/2008/06/hidden-xcode-build-debug-and-template.html

Become Productive in Xcode

Become Master of Xcode

Posted in Iphone, Learning, Objective-C, Software Development by Khang Vo on August 26, 2010

For iPhone development guys (and Mac as well), we all want to be as productive as possible. And one of our important tools is Xcode. I can even say that if we can master of Xcode, we can double our productivity. The reason is not only the time that the tool can save us but the number of times it breaks our workflow, or make us become bored/tired of our jobs. We are all humans, and no human in the world wants to do the job that a machine can do. Ok, stop talking and I will show you my summary of tips/tricks and techniques that I feel very very useful for me.

Many of these tips is from this stackoverflow post (I just list what I feel is most productive), 2 famous videos called “Becoming productive in XCode”, and a famous cheat sheet that almost all of us know “Complete Xcode Keyboard Shortcut List

I also recommend you to go there and take a look because this post may be really personal and lack excellent tips that you want.

1/ Basic Hot Keys

File Cursor Movement

  • Header/Source File Switching: Option + Command + Up Arrow
  • Last cursor point switch back and forward: Option + Command + Left (Right) Arrow


Quick Help/Documentation

  • Jump to Definition of a symbol : Command + Double-Click on a symbol
  • Find Text in Documentation of a symbol: Option + Double-Click on a symbol: (Only works if you have they symbol’s Doc Set installed.)


Auto Complete

  • (previous) next auto-completion argument : (Shift) + Control + /
  • Auto completion pop-up list : Escape or Control + comma
  • (previous) next Auto completion choices movement: (Shift) + Control + period


Text Movement:

  • Cursor movement between words : Option + Left (Right) Arrow
  • Cursor movement camel-cased parts of a word: Control + Left (Right) Arrow
  • Beginning or end of line: Command + Left (Right) Arrow


Interface Builder:

  • Jump to class in Xcode : Command + Double-click on an object in Interface Builder’s
  • Drag a customized object back to Interface Builder’s Library for later reuse.
  • Object overlap, see object menu under mouse: Control + Shift + Click on an object :


Code Organizing:

  • Bold line in the function list: #pragma mark Foo
  • Auto complete the pragma: pm or #p
  • Notation convention: // TODO: or // FixMe
  • Commenting a line: Command + /


2/ Advanced Hot Keys

With advanced hot keys, you will rarely need to use the mouse. Because, everything you need to do with the mouse, you can do it with the hot keys.

  • Open File Quickly : Command + Shift + D and don’t forget that open quickly uses the current word as a search term.
  • Popup list of methods and symbols in the current file : Control + 2
  • Look up current symbol:  Control + Command + ?
  • Editor area to full screen : Command + Shift + E
  • Debug and Editor Mode switch in All-In-One XCode mode : Command + Shift + B


3/ Some useful scripting

I will tell you more about scripting in the next part, but currently, I think this list is basic enough:

Default Auto Completion list, show when you type

defaults write com.apple.Xcode XCCodeSenseAutoSuggestionStyle List

Turn Off Undo Warning

defaults write com.apple.Xcode XCShowUndoPastSaveWarning NO

Logging class/method/variable name in Objective-C

Posted in Objective-C, Programming Language by Khang Vo on May 5, 2010

Just a small post for an effective tip in Objective-C.

Usually if you use the

NSString *name = @”Hello World”;

NSLog(@”%@”, name);.

Output: Hell world

And usually, when we debug the program and viewing the log, we really want to know the class/method/variable name and line number as well. You can manually hard code it like

NSLog(@”ApplicationDelegate – applicationDidFinishLaunching – name – Helloworld”);

But, it is really time consuming and repetitive task. For our company, we use


#define NCLog(s, ...) NSLog(@"<%@:%s:{%d}> %s = %@",
[[NSString stringWithUTF8String:__FILE__] lastPathComponent], \
 NSStringFromSelector(_cmd), __LINE__, #__VA_ARGS__ , \
 [NSString stringWithFormat:(s), ##__VA_ARGS__])

Another variant of this is (it combines both class name and method name into __FUNCTION__):

#define NCLog(s, ...) NSLog(@"<%s:{%d}> %s = %@", __FUNCTION__, __LINE__, \
 #__VA_ARGS__, [NSString stringWithFormat:(s), ##__VA_ARGS__])

Then you can just use it like NSLog. For example:

NCLog(@”Hello world”);

Output: <ApplicationDelegate:applicationDidFinishLaunching:100> name: Hello World

Good luck to your new productivity:). For your programming language, stop using the System.out.println() and Console.WriteLine, find a version of yourself

References:

http://stackoverflow.com/questions/2770307/log-the-method-name-in-objective-c

http://stackoverflow.com/questions/2818542/print-out-the-variable-name-objective-c