Xcode 4 NSLog Macro link in Xcode 3

妖精的绣舞 提交于 2019-12-24 06:19:30

问题


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(@"&lt;#Comment#&gt;");
</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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!