问题
In Xcode < version 4, there was a macro to quickly write NSLogstatements. I could type (I think, using my motor memory):
log control+.
And the code complete/macro would do:
NSLog(|);
| being the cursor.
Is there anything similar to accomplish this in Xcode 4?
Thanks
Ross
回答1:
I 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.
回答2:
Type NSL and press escape, the autocomplete will handle the rest.
来源:https://stackoverflow.com/questions/5817839/xcode-4-nslog-macro-link-in-xcode-3