How to create custom code completion macros in Xcode. I googled and find some methods, but I don't understand them completely. So can anyone tell me how to do it?
Thanks everyone..
How to create custom code completion macros in Xcode. I googled and find some methods, but I don't understand them completely. So can anyone tell me how to do it?
Thanks everyone..
This post from ablepear has a tutorial to add custom Text Macros. The following are the necessary steps, the tutorial specifies, to create a custom text macro for Objective - C.
Go to your Xcode application file (root/Developer/Applications/). Right-click (control-click) and Show Package Contents. Navigate to (Contents/PlugIns/TextMacros.xctxtmacro/Contents/Resources/). Select the Objective-C.xctxtmarco file and Copy it (command-c). Open a new Finder window and select your Home folder. Navigate to (Library/Application Support/Developer/Shared/Xcode/). In the Xcode folder Paste (command-v) the Objective-C.xctxtmacro file.
Open Objective-C.cxtxtmacro. It contains an Array with around 26 items, each of which is a Dictionary. Click on the "+" symbol/tab to the right of the selected cell. This will add a new Item to the plist root Array which will be our new entry (text macro definition).
Select the new Item and change the Type from String to Dictionary. Now tap on the disclosure triangle (the left side of the selected cell), this will rotate the triangle from pointing right (collapsed) to pointing down (expanded). You may also notice that the "+" symbol to the right changes into a set of lines when the Item is expanded. This let's us add "children" name/value pairs to our new Item.
There are a few "children" name/value pairs we need to add to our new Item to make it function and they are as follows:
Add the values to the keys. A typical macro looks like this (ex:NSLog text macro).
You can name your Identifier and CompletionPrefix whatever you'd like, as long as it does not conflict with any existing completion identifier. Here. flog, is used for Function Log.
Read the post in the above link, to understand in completely.
IMPORTANT UPDATE: It seems the above v macro doesn't work in Xcode 3.2. To make it work we have to add the key,
OnlyAtBOL = YES; // or NO
to each macro definition in your xctxtmacro file. This key specifies that the macro works only at Beginning Of Line, or not at the the beginning of line ie., works only after the beginning of line . So the flog macro will look like this.
{
Identifier = objc.flog;
BasedOn = objc;
OnlyAtBOL = YES;
IsMenuItem = YES;
Name = "Function (NSLog)";
TextString = "NSLog(@"FUNCTION: %s", _FUNCTION_)";
CompletionPrefix = "flog";
}
I hope this will be of some help to someone in future.