I have fallen in love with visual studio's code snippets toolkit. Is there anything similar on Xcode?
You can also take a loot at this question which is about similar issues with XCode 3 (code templates, code completion, and more).
Xcode 4 has support for code snippets.
Of course there are. They are under "Edit -> Insert Text Macro".
Or you can simply start typing 'if<ctrl+.>' and this will be expanded into the full if statemenet.
Related
I want to ask you if there is any code arrangement functionality in XCode 7+?
I ran into a situation where I want to make my code more readable and organized. For this I have to (re-)sort some functions and elements (Swift) inside some source code files.
Being also an Eclipse and IntelliJ user I am used to have a couple of options, like rules-based auto-sorting or an outline view where I can move functions etc. around. Haven't seen something like this in XCode so far - sure, there is an "outline view" (aka. Symbol Navigator), but it is really only a viewer. -.-
I also know about the CMD+Opt+[ / ] shortcuts but this kind of manual sorting is tedious.
Is there a better way? Thank you.
Martin
As of Xcode 7.3, there is no better way of doing what you want. As an IntelliJ user, you may want to try AppCode by JetBrains.
Xcode code formatter Swift
I'm trying to auto format my code written in Swift. It's necessary if you're working in team and using CVS and don't want to merge for hours.
Ctrl+I just makes an indent, but for example i want to have proper space between functions and just all the stuff like in Clang.
The reformat code command in xcode is Ctrl-I, not Cmd-I and it appears to work just fine.
I write a extension app about format Swift code: Swimat
There has two way to install
brew cask install swimat
Clone this repo, build and restart Xcode.
See https://github.com/Jintin/Swimat for more information
In Xcode [Objective-C, Swift]:
1) ⌘+A: highlight code
2) ⌃+I: reformat code
⌃+i: reformat code
Ctrl+i: fix code indentation
Eventhough it has good IntelliSense, xcode sucks at code formatting generally.Wish it was better.
Apple has to spend so much effort in this in order to make it VS level good.
Xcode and Swift 2.0: Per file, Cmd-A then Ctl-I. Ctl-I works for what is highlighted, Cmd-A highlights all. Just be careful not to accidentally delete all your source after the Ctl-A!
SwiftFormat is a popular code formatter for swift. It has an extension for Xcode, which can be accessed from the Editor menu.
Quote from the SwiftFormat readme:
SwiftFormat is a code library and command-line tool for reformatting
swift code on macOS or Linux.
SwiftFormat goes above and beyond what you might expect from a code
formatter. In addition to adjusting white space it can insert or
remove implicit self, remove redundant parentheses, and correct many
other deviations from the standard Swift idioms.
(I know the question says Xcode but)
personally this is another reason to use AppCode alongside Xcode.
While Xcode only fixes the indentation for Swift code, as mentioned in the question, AppCode at least handles spaces too. Somewhat relatedly it removes indents from empty lines by default.
AppCode's Swift support definitely isn't perfect yet and you still need to check the code in both, but it's still worth it because of better navigation and things like this.
The command in xcode is ctrl-i to format code, not cmd-i.
I would suggest using sublime text with the swift plugin, which will allow you to hotkey the code formatting.
https://sublime.wbond.net/packages/Swift
Select lines, then press Ctrl+I.
I don't like the way Xcode displays compile errors and highlights source code in a separate floating Build Results window. It's easy to end up with 3 text editors on screen, all showing the same source code! I just want it to jump to my error in the main text editor like Visual Studio would. Is there a way around this, or is it any different in Xcode 4?
Yes, select the "All in one" layout in XCode General Preferences.
Yes, Xcode 4 is all one window, and builds constantly so errors appear almost immediately. I think you'll like it much better, especially if you're accustomed to Visual Studio (it's not the same as VS, mind you, but more similar than Xcode 3).
No way mate, I was a .net developer before I switched to mac. It's very hard to get use to Xcode and Objective C, it's not as intuitive as Visual Studio , or C sharp.
However the latest version of Xcode brings some improvements , so it doesn't show you the compiler errors in a separate window. It shows you the errors in the left side and the code in the editor. you should upgrade it's a bit more intuitive.
Has any one found a replacement for Rockscroll or Metalscroll for Visual Studio 2010?
I miss it so much that I looked into making one my self but only have word highlighting working and a place holder scroll bar and seems to be much harder than I thought it would be. I'm happy to share what I got if someone is interested in helping.
The Productivity Power Tools extension for VS2010 just added an "Enhanced Scrollbar"!
To enable the minimap go to Tools->Options->Productivity Power Tools->Enhanced Scroll Bar and check "Full map mode". Optionally you can assign the background color and highlighted region.
Just tried ProgressiveScroll and it looks and feels like the original MetalScroll; it also works in Visual Studio 2012!
A user named Kryo at the "Sins of solar empire" forum have made a pretty good imitation of MetalScrollbar for VS 2010, called MetalMargin. Available here. Just installed it, and it seems to work pretty well, although highlight on double click is not yet implemented.
David Pugh released a version of his Structure Margin, which serves a similar purpose. His All Margins extension combines a bunch of the other smaller extensions in the same vein.
It's not exactly the same, but I find the structure margin to be an interesting way to visualize the entire code file.
I haven't tried it myself yet but AllMargins looks really nice. Whoops you already linked it Noah Richards. Sorry.
The code is also available for the OverviewMargin - I haven't tried it at all, but it may be a good place to start from if you want to roll your own.
Did You try RockMargin ?
http://visualstudiogallery.msdn.microsoft.com/1b0d7360-40dd-447e-8bef-90e2cf52f683
This is useful
For anyone looking for a replacement for just the Highlighting part of RockScroll, the free plugin "Highlight all occurrences of selected word" does exactly that.
I'm trying to use the simple pre-installed code snippets in VS2008. I can insert them by right-clicking and using Insert Snippet..., but I can't get them to work while typing. If I start to type "for", I get the Intellisense list, and I see an entry for the code snippet, but hitting Tab or Enter just inserts the word for, not the snippet.
What am I doing wrong here?
try hitting tab once more..
Or in Emacs style
ctrl-k ctrl-x
It could be your using any kind of VPC software that is intercepting your tab commands and inject them into VPC with a wrong code. I havent found a solution yet though.
Which language you are using?
C++ snippets don't work in VS2008. MS took that feature out :(