Xcode 8 auto-generated quick help documentation - xcode

Among the new features announced in Xcode 8, we can see
"Auto-generate Quick Help documentation" :
Is this the end of manual code documentation like we can learn on this article from NSHipster ?
Can someone outline the pros and cons of this new feature ? Does it replace tools like Jazzy ?
I couldn't find more information about the new feature.

This refers to Xcode 8 (and later) feature, where you can select a method like this:
func foo(bar: Int) -> String { ... }
... and then press ⌘+option+/ (or choose “Structure” » “Add documentation” from Xcode's “Editor” menu) and it will generate the following comments template for you:
/// <#Description#>
///
/// - parameter bar: <#bar description#>
///
/// - returns: <#return value description#>
It just facilitates the writing of documentation for Quick Help.
Note, while this behavior has changed a bit over time, Xcode can be particular about where the cursor must be when you attempt to do this. For example, the cursor has to be somewhere in the function name, foo in my above example, for this to work. Or just double click on the function name and then press ⌘+option+/
You asked whether this feature replaces tools like Jazzy.
No, it doesn’t replace Jazzy or similar tools. Amongst other things, Jazzy creates stand-alone HTML documentation from this inline documentation. So, it is simply a question of whether you need these stand-alone outputs from Jazzy for any reason. If so, use Jazzy (or similar tool) in conjunction with this integrated documentation. If not (i.e., you are only looking for documentation from within the Xcode IDE), then Jazzy is not needed.

This is most likely related to the fact that ALL hotkeys with a '/' don't work in the current XCode 8 build, if your keyboard requires to press shift to get it.
I.e. on the german keyboard the '/' is shift+7, pressing alt+cmd+shift-7 doesn't do a thing. If you assign i.e. cmd+shift+opt+d, it works just fine.
The shortcut '///', which unfortunately also doesn't work right now, is probably due to the old XCode plugin VVDocumenter, which used exactly this shortcut.
Great feature, lousy QA on the Apple side.

Related

Xcode shortcut to implement protocols in Swift [duplicate]

When I use a prototype table view, I always have to conform to the protocol TableViewDataSource. I always forget what methods I need to implement, so I have to look at the source of the protocol every time. This is really time consuming.
I think Xcode must have a feature that automatically implements the needed methods for you, right? Just like IntelliJ IDEA, Eclipse, and Visual Studio.
I want to know where can I find this feature. If there's isn't, is there a workaround for this? At least I don't have to open the source code of the protocol each time I conform to it.
If you don't understand what I mean, here's some code:
I have a protocol
protocol Hello {
func doStuff ()
}
When I conform to it,
class MyClass: Hello {
}
I often don't remember the names of the methods that I need to implement. If Xcode has a feature that turns the above code, into this:
class MyClass: Hello {
func doStuff () {
code
}
}
Now you understand what I mean? I just want to ask where to find such a feature.
Xcode 9 : you can add missing Protocol Requirements by add new shortcut to your Key Bindings Set
From the top Xcode menu (top left) choose Preferences.
Choose Key Binding.
Search about protocol. you will find Command called Refactor -> Add Missing Protocol Requirements
Press on Key column then add your shortcut. ex: cmd + shift + M
Now you can add missing Protocol Requirements by clicking on class name name (or his extension) then press your shortcut
Well if i understood your problem then here is a workaround:
try to define methods with protocol as prefix like here hello then you'll not have to remember the methods just start typing protocol name and XCODE will prompt you with all available methods see here:
And if you want autocomplete protocol try
Snippets
Xcode 9, takes care of implementation of mandatory methods of Swift Datasource & Delegates.
Look at these snapshots, with example of UICollectionViewDataSource:
Indicating warning to implement protocol methods:
By clicking on 'Fix' button, it has added all mandatory methods:
Very similar to Amjad's post, Xcode 9/10 brings the functionality to add missing protocol requirements right from within the code editor.
Just "right click" on the class name: "Refactor" --> "Add Missing Protocol Requirements"
Xcode won't do it for you.
If you look at the documentation for the protocol, it's clearly marked which functions you have to implement:
https://developer.apple.com/library/ios/documentation/UIKit/Reference/UITableViewDataSource_Protocol/

Swift code completion isn't working

I installed Xcode 6.0 beta and downloaded the iOS8 library Documentation.
but when i create a Swift project, try to typing code
func aa(){
let format = NSDateFormatter()
var pageData = format.
}
I find Xcode can't dot any property and function. Am I missing any step?
The problem is sloved, typing a whitespace can aid code completion
It's append when you change the hardware type and you choose less than iphone5.
Choose Iphone 6 for example in the list at the right of the stop button and the code completion for 'format' will appear.
I met the same problem and solve it by removing the non-ASCII char in comment (in my problem, it's a chinese char "年" automatically generated in comment by xcode).
btw. "typing a whitespace can aid code completion" doesn't work for me
It’s a bug, your code works on my system (OS X 10.9). Note that when typing code, I sometimes see the code completion crash for two seconds and come back.
When trying a first project named "swift", code completion crashed in a infinite loop… beta bugs… I just had to name it something else to test the language.
You know, I've experienced something similar with Objective C projects in Xcode 6 Beta 1. It seems Apple have changed the default behaviour a bit:
In Xcode 5.x code would always automatically complete as you type, but in this early beta try pressing ESCAPE - that will bring up the list you're looking for. Works for me. Some code auto completes as you type (both in Swift and Objective C), but at times only ESCAPE will bring up what we're looking for.
I'm nor sure if this is expected behaviour or a bug (I'm guessing the latter).
I must admit that your code works fine on my system without this trick. Just make sure you have code completion setup under Xcode - Preferences - Text Editing:

Xcode, see where a method is used

I have a method in some class and i would like to see exactly where it is being used. Compared to Java and Eclipse you can simply tell it to show all the references and even a call hierarchy of a method. Is there anything similar in Xcode?
I know that Objective-C does not follow the same ways of identifying method signature as Java does (i.e. there is no method to a class, just a bunch of selectors mapped to an id at runtime), so i'm having a hard time trying to figure out how Xcode could even accomplish this.
Look here:
There is no equivalent menu or context menu.
In addition to callers you can access callees, superclasses, etc.
If you don't use Ctrl-1 for Spaces you can access that menu with it.
Note that you need to use the Standard or Assistant Editor:
Callers and callees are not shown if the Version Editor is selected:
Your best bet is likely string searching, but realize that you can use patterns (click the little magnifying glass in the search bar in the file browser pane).
You've hinted at one of the reasons it's so hard to do otherwise. Objective-C's runtime allows many different ways of finding and executing code.

Xcode Documentation Generator

I've looked at Headerdoc and Doxygen for documenting source code, but they both seem to need the developer to do most of the leg-work first. In Visual Studio, typing \\\ generates the skeleton for documentation including the parameters expected by a method. There's also Ghostdoc which guesses what the method does based on its name and parameters. Is there anything similar for Xcode?
There is also Appledoc, which creates a variety of documentation from comments in your source, docsets, html that looks just like the Apple docs.
You can use VVDocumenter plugin, it's a very handy plugin for XCode documentation.
After that you can find the method (or any code) you want to document to, and type in ///, the document will be generated for you and all params and return will be extracted into a Javadoc style, which is compatible with Appledoc, Doxygen and HeaderDoc. You can just fill the inline placeholder tokens to finish your document.
Download the XCode package manager: Alcatraz which can be done easily with the following command:
curl -fsSL https://raw.github.com/supermarin/Alcatraz/master/Scripts/install.sh | sh
Restart XCode and you will find a new option in the Window toolbar menu labed 'Package Manager'. You can then install VVDocumenter from there.
Once you install VVDocumenter you'll need to restart XCode again, but after you reload Xcode you can then type /// to get help writing comments which will later be used to write your documentation.

xcode 3.2 c++: how can i enable a proper code completion?

I have snow leopard and I'm building a cpp Application with xcode.
I would like to be able to get proper code completion with xcode, and by that i mean the following:
std::string f;
f.
just when I type f. i would like to see all the relevant functions to that string class. is it possible in xcode ?
You just need to press the ESC key to get the code completion menu to show.
It may seem counterintuitive but press the ESC key after the period.
If you want the completion menu to display automatically, you can also set that in your preferences:
Code Sense -> Code Completion -> Automatically Suggest

Resources