Is there a way to make Xcode handle brackets more intelligently? - objective-c

In Xcode, if you are calling a method that takes a series of flags as an argument, when you type the right bracket character, it creates a new left bracket at the last flag, rather than at the start of the line. Is there any way to fix this?
// Type this...
someFunc withFlags:FlagA|FlagB|FlagC
// Now type a right bracket ]
someFunc withFlags:FlagA|FlagB|[FlagC ]
// It should be this:
[someFunc withFlags:FlagA|FlagB|FlagC]

Turn-On Xcode->Preferences->TextEditing->Editing->Automatically balance brackets in ObjectiveC method calls
I'm using Xcode Version 5.0.2 (5A3005). The below both of them worked fine for me.It automatically created left bracket when I closed the right one.
[self someFunc:1 Flag:YES|YES|YES];
[self someFunc:YES|YES|YES];
- (void)someFunc:(int)x Flag:(BOOL)yes
{
}
- (void)someFunc:(BOOL)yes
{
}
Here is my Xcode settings

There is no way, unfortunately. Although, filing a bug report to Apple will make this more likely to get fixed. If this behavior breaks your flow, you can always turn it off in the settings. Xcode -> Preferences... -> Text Editing -> "Automatically insert closing braces ('}')"

Type the first bracket when you start the line.
That is what you should do first.
Also you should use parentheses around your flags.

Related

How to get output of Kotlin IntelliJ scratch file?

A script as simple as
println("a")
doesn't produce any output in the Scratch output window. I expect an a to appear in the output window.
I'm using IntelliJ 2019.1.2 CE.
EDIT: Information regarding the expected functionality
According to a question I had asked: IntelliJ Ultimate Kotlin Script REPL skips first printed lines - Scratch Output cut off
It seems to be the case that the REPL wants to output per line, and will only overflow into the bottom area after a certain line length is reached.
In the question I state that I generally add some initial padding so that it always flows into the lower area with something similar to:
repeat(10) { println("BLANK ") }
END EDIT
You have to make sure that Interactive Mode is turned off at the top of the scratch window
This will cause prints to be put into the Scratch Output window.
Be warned, atleast in the version I have of IntelliJ ultimate 2019.1.3, the first 5-9 lines generally dont print so I do something like:
repeat(9) { println("blank") }
If you've defined everything inside of a function, the script won't execute the function automatically - you'll need to explicitly call the function.
You can create your own print, like this:
fun <T> myPrint(x: T) : T = x
then calling e.g.:
myPrint(5)
should show 5 in the result window.

Pharo: customizing smart characters

The checkbox "Smart Characters" in "Code Completion" section of Settings Browser does (at least) two things:
1) It doubles some characters when typed: ', ", (, [, {
2) It enables that I can select a piece of code, press ( (i.e. Shift+9), and the selected code becomes surrounded by parentheses: (). I also can remove parentheses by pressing ( again. I also can do this with [] by pressing [ and with {} by pressing {, i.e. Shift+[.
I do not like the first of these things so I want to disable it, but I like the second thing and want to keep it. How can I achieve this? Turning off the checkbox will disable both.
P.S. I know that when the checkbox is off, adding/removing parentheses works by Cmd+Shift+9 (which is less convenient than Shift+9) and that Cmd+[ works for [], although I do not know any working shortcut for adding/removing {} when the checkbox is off.
The setting is called "Smart Characters", which should give you a clue as to where to look. Open a Finder, type in smartCharacters, and hit Enter. You should see some partial matches as well as an exact match for NECController and NECPreferences class (and the former just calls the latter). If you investigate the classes involved a bit, you'll see that smartCharacters stores a boolean, and that smartCharactersMapping returns a dictionary mapping some characters to their "counterparts", i.e. $[ to $] and so on. Now look at senders of smartCharactersMapping, and you'll see where it's being called from.
The caller you're most likely interested in would be NECController>>smartCharacterWithEvent. So put a breakpoint in that very ugly method to see what it does. You don't care about the first two cases (the editor having a selection and there not being a smart mapping), since you want to prevent the second matching character from being inserted. So the interesting bit for you is this bit:
self newSmartCharacterInsertionStringForLeft: char right: opposite
The method only has one implementor and that one sender, so it should be safe to comment out the original method and just return the "left" character, i.e.:
newSmartCharacterInsertionStringForLeft: left right: right
^String with: left
In other words, instead of creating a string with the left and right characters, and possibly spaces between them, just return a new string with the single character you typed. Might not be the most elegant way of solving this, but it should work, and should show you how to solve similar problems in the future.
(Ideally, you'll find a better solution, post it here as an alternate answer, and contribute it to the Pharo codebase - Pharo is open source, after all.)

Reformatting to have method parameters in a new line

There are so many settings in the preferences for Code->Style->Objective-C. I'm looking for the right one to reformat this line of code
SCPropertyDefinition *test = [SCPropertyDefinition definitionWithName:#"created_at" title:#"Tweeted At" type:SCPropertyTypeLabel];
to this format
SCPropertyDefinition *test = [SCPropertyDefinition definitionWithName:#"created_at"
title:#"Tweeted At"
type:SCPropertyTypeLabel];
(the point is to have the colons indention matching)
I guess the it should be in the Wrapping and Braces Tab, but I havn't found the right setting yet.
Thanks for your ideas.
The setting you are looking for is Wrapping and Braces | Method call arguments set to Chop down if long with enabled Align by colon. Note that there are separate settings for Method parameters.
It seems like as of App Code 2017.1 (perhaps earlier too) the align by colon option is not available in Swift. You can still tell App Code to chop a long argument/parameter list:

Xcode does not automatically indent on colon for a method name split across lines

I'm expecting Xcode to auto-indent my method when I type a colon, but it does not. I have Automatic indent for: ":" turned on. How can I get this to work?
Example:
type - (id)initWithName:(NSString *)name
press return
type value:(int)aValue
press return
type number:(int)aNumber;
press return
This is what I get
- (id)initWithName:(NSString *)name
value:(int)aValue
number:(int)aNumber;
Why didn't it indent the second line??
I'm not sure the "why" is really answerable; it's annoying to be sure that Return doesn't seem to trigger auto-indent sometimes.
There's a workaround, though: before moving to the next line, you can type a semicolon. That triggers the indentation, and you can then delete it and hit Return.
It'll also indent properly if you type the method name out on one line first and then go back and insert the line breaks.
Neither of these are particularly wonderful options, of course.

Expression in Xcode 4.3.2 Debug area not evaluated

I'm doing something wrong. I have added an expression, I can see the expression with the "E" symbol in the Debug area, but the expression is not being evaluated, its value is not displayed there (it is in scope at that time).
When I use the debugger (lldb) directly, it works well.
Xcode 4.3.2.
What should I do?
Thanks
You are trying to evaluate a boolean and print it as an object.
You want to use print [self isEditing] or print (BOOL)[self isEditing], depending upon whether the debugger complains that it doesn't know the type of the member or not.
The po command prints an object description, not an arbitrary value, and should only be used when the result of the expression on the right is an object, such as po self.
The same problem occurs in the expression editor. If you use the expression [self isEditing], the debugger won't understand it. However, if you use (BOOL)[self isEditing], it will display correctly.
try adding the expression as self.isEditing, without the square brackets. Works here