和这篇文章一样,以下基本都是从becoming productive in xcode中取得的
===Text Macros===
添加自己的TextMacros(XCode 3.2.5测试通过,XCode 4 未测试)
在~/Library/Application Support/Developer/Shared/Xcode/下面新建Specifications文件夹,建立与/Developer/Applications/Xcode.app/Contents/PlugIns/TextMacros.xctxtmacro/Contents/Resources文件夹下类似的*.xctxtmacro文件即可
例子
(
{
Identifier = objc.hello;
BasedOn = objc;
IsMenuItem = YES;
OnlyAtBOL= YES;
Name = "Hello";
TextString = "Hello, XCode!";
CompletionPrefix = "hello";
IncludeContexts = ("xcode.lang.objc");
},
{
Identifier = objc.property;
BasedOn = objc;
IsMenuItem = YES;
OnlyAtBOL= YES;
Name = "@property Definition";
TextString = "@property (nonatomic, retain) IBOutlet <#type#> *<#variable#>;";
CompletionPrefix = "prop";
IncludeContexts = ("xcode.lang.objc.interface");
},
{
Identifier = objc.rectmake;
BasedOn = objc;
IsMenuItem = YES;
OnlyAtBOL= YES;
Name = "RectMake";
TextString = "CGRect aRect = \n\tCGRectMake(<#x#>, <#y#>, <#width#>, <#height#>);";
CompletionPrefix = "cgrm";
IncludeContexts = ("xcode.lang.objc.block");
}
)
上面的代码添加了三个textmacro:
第一个仅仅是测试用,代码中输入hello即有自动补全提示,补全成Hello,Xcode!。
第二个效果是输入prop,然后 ⌃. 自动补全成@property (nonatomic, retain) IBOutlet <#type#> *<#variable#>;的形式,具体实验一下就知道了。
第三个类似,不多说了。
首先注意一下OnlyAtBOL这一行,在新版本的XCode中如果不加上这一行则textmacro无法生效。具体请看这一段的解释:
There is a bug on TextMacros in the latest versions of Xcode (I encourage you to send a bugreport to Apple as I did)