For some reason Xcode identifies strings, methods, objects & more as plain text. This applies with all the themes Xcode has to provide me with. This is a C++ file.
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 use Xcode with the key bindings heavily overriden to match my taste, for example, I use Alt+[/] as shortcuts for the "Jump to previous/next placeholder" commands. Unfortunately, with the latest 4.4.1 update these bindings stopped working and now I'm getting quote characters (“‘) dumped into the text editor instead. The binding setup is still marked as valid (no conflicts are reported by Xcode). Any thoughts on this?
OSX 10.7.4, Xcode 4.4.1 (4F1003), standard US layout, alu keyboard if that matters.
Ok, turns out there are multiple entries for the seemingly same function, as shown in the image below:
Setting both to the same binding did the trick.
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.
I'm working with some OpenCL code in Xcode 4. I don't want to compile the code with Xcode - that's done dynamically by the C++ code. Xcode 4 doesn't know about OpenCL syntax coloring. How can I tell it to apply C syntax coloring instead?
(It's not just for coloring. It also gets indenting wrong etc.)
xCode Menu [Editor]->[Syntax Coloring] doesnt work?