Navigating autocomplete entries in XCode - xcode

Sometimes when I type certain words, XCode will offer to autocomplete with several options. If I press enter, it automatically puts the curser on the first option and selects it so when I start typing that part gets replaced. After that, how do I immediately get to the next option, without having to double click it?
For example, if I type the following:
UIAlertView *alert = [[UIAlertView
alloc] ini
Then Xcode offers to autocomplete with the following:
UIAlertView *alert = [[UIAlertView
alloc] initWithTitle:(NSString
*)title message:(NSString *)message delegate:(id)delegate cancelButtonTitle:(NSString
*)cancelButtonTitle otherButtonTitles:(NSString
*)otherButtonTitles
Everything that appears above in bold is highlighted, meaning they are to be replaced by the programmer. If I press enter to accept the autocomplete, Xcode will put in the above code, and select the first highlighted item, which is (NSString *)title. If I start typing something, this is immediately replaced by what I type. When I'm done replacing this, I want to move directly to replacing the next highlighted item, which in this case is (NSString *)message. I can do that by double clicking on it, but is there some kind of keyboard shortcut that will get me directly there?

Press Control.
Or press Esc to enter the list of completions.
Edit: Aha! Now I know what you mean. You want Control/.

Press the TAB key to move to the next highlighted item and SHIFT + TAB to move backwards through the same list.

Related

How can I put multiple lines of text in an NSMenuItem?

I would like to create an NSMenuItem with more than one line of text in it, and I'd also like an icon to appear next to both lines of text. I can't use a custom view, because then it wouldn't highlight correctly, and I can't just put a newline in the menu item's title, because the newline gets turned into a space. What should I do?
It turns out that although you can't put a newline in the title property of a menu item, you can put a newline in the attributedTitle. Something like this will work:
item.attributedTitle = [[NSAttributedString alloc] initWithString:#"line 1\nline 2"];

How do you deal with Xcode's irritating auto completion behaviour for blocks?

XCode's auto completion can sometimes be a pain in the butt, here an example:
It seems impossible to just type in some content to replace the completionHander placeholder without deleting the entire highlighted section of text - if I hit tab and start typing then Xcode deletes everything highlighted in blue, when what we want to do is keep the ^(NSArray *placemarks, NSError *error) part and type in our own content in place of the completionHandler placeholder.
Are there any tricks to keep auto completion enabled for cases when its useful, but to get this and similar examples usable instead of unusable?
Hit Tab, but instead of starting typing, just press Enter. Xcode will expand the selection into a block with empty implementation.
Before:
After:
When the placeholder for the block is highlighted, press Return. It'll be replaced by the complete block declaration and a set of empty braces, with a highlighted placeholder inside for you to start typing code for the block's body; e.g.
[geocoder reverseGeocodeLocation:location
completionHandler:^(NSArray *placemarks, NSError *error) {
<code>
}]

What is Jump to Next placeholder shortcut key in Xcode is supposed to do?

I have used it, but i'm not sure what it does!
And also Jump to Next PlaceHolder to do? No idea on this shortcut key too!
A placeholder is the fillable area in an auto-completed code snippet.
Say I type [UIView ani, XCode will autocomplete to this :
The placeholders are the three pieces of code on gray background, which you can double-click to edit.

How to make Xcode auto-complete act like bash auto-completes file names

If I type UITa, then it might show an autocompletion of UITableViewDataSource. So I press enter and that's what I get. But what I wanted was UITableViewDelegate. If this was when we input the file name in the command line of bash, then it would have auto-completed up to UITableViewD, and then I would have to enter a to get an autocompletion for UITableViewDataSource, or e to get UITableViewDelegate.
Is there a way to make Xcode work like that, or another way to avoid this problem?
In my machine (XCode 3.2.3 on OS X 10.6.4) the auto-completion works exactly as you described you want to behave.
Typing
NSMut
shows something like
NSMutableArray
Note that NSMut, able, and Array are all displayed in a different color/font in XCode.
Typing D here to change the completion to NSMutableDictionary does not work, but hitting Enter or the right arrow key changes the selection up to
NSMutableArray
Hitting D here changes the completion to
NSMutableDictionary
If you want the possible list of auto-completions, just hit the escape key. Hitting escape key is the general way to get the list of completion in any Cocoa app on OS X. In any Cocoa text box you'll get the list of English words which matches the first few letters you typed.
Xcode autocompletion can be inconsistent. Workaround: After typing some characters, hit ESC and Xcode will pop up a scrollable list of completion options. Continue typing to narrow down the list. Use the up/down arrow keys to navigate the list. Hit return to complete using the selected text. This approach can be helpful when Xcode autocompletion is acting flaky.

Xcode auto-completion - replace text keystroke?

Say we have a TestClass with the 2 methods, -getSomeString and -getAnotherString, and we are editing the following code and the cursor is in the location shown:
NSString *aString = [TestClass get<cursorIsHere>SomeString];
Say I want to change it to use -getAnotherString. If I bring up the auto-completion popup and select the other method via hitting enter or tab, I'm left with:
NSString *aString = [TestClass getAnotherStringSomeString];
i.e., it doesn't replace the existing text but rather just inserts.
Is there a special keystroke to make it replace the remaining text?
See IntelliJ for reference.
I don't think that there is a one step operation to achieve this. My suggestion would be similar to Thomas Templemann, but rather than two steps of forward word select and then Delete, I would expand to the desired autocomplete, by bouncing on Control + . and then hit Option + forward delete, which kills to the end of the word.
I don't think so. I have always used the following
double click on getSomeString
press Escape (or your autocomplete key)
find replacement method
that double click step has never really bothered me, but I would be interested if anyone knows better!
My work-around for this problem is this: Since the cursor will be right after the inserted text, I just press Shift-Option-Rightcursor, which selects the word past the cursor, then I hit the Delete key.
You can use the Tab key to perform "replace" instead of "insert" when choosing the method from the auto-complete popup in IntelliJ 9 (don't know if it's available in previous versions).

Resources