这不完全遵循 Apple 建议的格式,也没有直接回答您的问题,但我想我会分享这些方便的花花公子的文本宏,我在制作通知和键名时使用这些宏来节省自己的一点打字时间。您可以为这些分配一个键盘快捷键,输入并选择[Did|Will] + [UniquePartOfName]
段,然后点击快捷键以生成变量及其值。如果您在特定类的标题中定义这些字符串,您也可以使用$(FILENAMEASIDENTIFIER)
而不是,这将符合建议。$(PROJECTNAME)
//MARK: Notification strings
{ /*
* Use the selection to make the name and string for a Notification.
* The string has a prefix placeholder, defaulting to the project name.
*/
Identifier = objc.notestring;
BasedOn = objc;
IsMenuItem = YES;
Name = "Notification Name From Selection";
TextString = "<#$(PROJECTNAME)#><#!notename!#>Notification = @\"<#$(PROJECTNAME)#><#!notename!#>Notification\";";
CompletionPrefix = notestring;
},
{ /*
* Insert placeholders to make the name and string for a Notification.
* This is for use without a selection, and so "only" activates at the
* beginning of the line.
*/
Identifier = objc.notestring.bol;
BasedOn = objc.notestring;
IsMenuItem = YES;
Name = "Notification Name From Selection";
OnlyAtBOL = YES;
CompletionPrefix = notestring;
},
//MARK: Default Key strings
{ /*
* Convert the selection into a name and string for use in the User
* Defaults system. The string has a placeholder for a prefix, which
* defaults to the project name.
*/
Identifier = objc.defaultskeystring;
BasedOn = objc;
IsMenuItem = YES;
Name = "UserDefaults Key From Selection";
OnlyAtBOL = NO;
TextString = "<#$(PROJECTNAME)#><#!keyname!#>Key = @\"<#$(PROJECTNAME)#><#!keyname!#>Key\";";
CompletionPrefix = defaultskey;
},
{ /*
* Insert placeholders to make the name and string for a a key for the
* User Defaults system. This is for use without a selection, and so
* "only" activates at the beginning of the line.
*/
Identifier = objc.defaultskeystring.bol;
BasedOn = objc.defaultskeystring;
IsMenuItem = YES;
OnlyAtBOL = YES;
Name = "UserDefaults Key From Selection";
CompletionPrefix = defaultskey;
},
这些是 Xcode 3 宏。我知道宏系统在 Xcode 4(我还没有使用)中有所不同,但我相信转换很简单并且可以自动化。