Xcode 4 NSLog Macro link in Xcode 3
In Xcode < version 4, there was a macro to quickly write NSLog
statements. I could type (I think, using my motor memory):
log control+.
And开发者_StackOverflow the code complete/macro would do:
NSLog(|);
|
being the cursor.
Is there anything similar to accomplish this in Xcode 4?
Thanks
RossI really miss this macro too. Thanks to Kendall's example, I was able to recreate it.
Go to this folder or create one if doesn't exist:
~/Library/Developer/XCode/UserData/CodeSnippets
Then create a file called NSLog.codesnippet and paste in the following:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>IDECodeSnippetCompletionPrefix</key>
<string>log</string>
<key>IDECodeSnippetCompletionScopes</key>
<array>
<string>All</string>
</array>
<key>IDECodeSnippetContents</key>
<string>NSLog(@"<#Comment#>");
</string>
<key>IDECodeSnippetIdentifier</key>
<string>nslog1</string>
<key>IDECodeSnippetLanguage</key>
<string>Xcode.SourceCodeLanguage.Objective-C</string>
<key>IDECodeSnippetTitle</key>
<string>NSLogComment</string>
<key>IDECodeSnippetUserSnippet</key>
<true/>
<key>IDECodeSnippetVersion</key>
<integer>2</integer>
</dict>
</plist>
Restart Xcode and type l into a file in your project. If autocomplete isn't showing, hit escape and then choose the "log - NSLog comment" option and then hit tab.
After you've used it once, you'll probably only need to use l+tab for the autocomplete.
You can create as many as you like. Just make sure the filename, the IDECodeSnippetIdentifier and the IDECodeSnippetCompletionPrefix are all unique.
More examples are available on GitHub.
Type NSL
and press escape, the autocomplete will handle the rest.
精彩评论