Converting a .storyboard file into raw swift code in Xcode 6 - xcode

Is there a program that can take a .storyboard file, and convert it into Swift code? An example being: If I have a UIViewImage element in my storyboard can the program identify the element and convert it into swift, then insert that code into my viewcontroller.swift file? (Just an example.)

AFAIK, no.
There's this rather old nib2objc tool that convert from NIBs to Objective C code. But no Storyboard -> Swift tool that I know of.

Searching for the same thing, I discovered this tool and ran the demo on one of my Xcode 10-14 era storyboard files. It seems to work as advertised, including having an interactive mode that allows highlighting sections to find what corresponds:
https://www.microcodingapps.com/
Disclaimer: I have no connection with this app or whoever makes it and have only taken a cursory look at it so far, but I was impressed enough with what I saw to come back to this SO article and add an answer.

Related

Swift 3.0 quick help option key

I'm a total beginner in Swift, so I always find the quick help in Swift 2.2, Xcode 7 very useful(You hold down option key and click on something and the Xcode would give you a pop-up window containing all sorts of information about the variable you are clicking on). However, after I updated to Swift 3.0 the pop-up window becomes blank and a message "No Quick help". I'm wondering if someone could tell me how to bring the quick help back, thank you!
This is an Xcode question. Quick Help only works with Swift when you don't have any errors before or in the current line you want to open the Quick Help from.
I also experienced this and it seems this feature worked much better with older Xcode versions. But I guess this has to do with Swift because it is such a fast growing programming language. The integrated interpreter of Xcode isn't able to keep up with it.
To work around it, just comment out all failing lines of code and then comment in one line by one while fixing the errors. Sometimes it is helpful to also clean up the generated project files. And if this also doesn't work, just restart Xcode.
The last step is often necessary when you're in a Playground.

XCode 7 - How to rearrange source code elements

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.

How to use code formatter in Xcode for Swift?

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.

Is there a way to tell XCode to always display "Counterparts" in the Assistant editor?

Side-by-side .m and .h files are maybe my favorite thing about XCode 4. Of course, there's gotta be a catch: XCode switches to "Manual" sometimes, showing some other random .h file. Switching among tabs, I frequently start writing in a .h which isn't actually the right one. I usually notice this pretty quickly, but it's annoying.
Is there a way to tell Xcode to always display the 'Counterparts' view, i.e. the .h to whatever .m I have in the primary editor?
EDIT: My workaround is the wonderful hand-twisting shortcut Shift-Option-Cmd-Z, which brings up the counterpart whenever Xcode decides to get all cute and show some random other file.
Not currently, no. File an enhancement request at http://bugreport.apple.com
FYI, my own experience with this annoyance is usually caused by accidental trackpad navigations while my pointer is over an assistant pane.

Whats the best way to manage code snippets on Xcode?

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.

Resources