Replies: 6 comments
-
This is a tough one. What do we do in the last example if the capture list exceeds 100 characters? |
Beta Was this translation helpful? Give feedback.
-
I personally have not yet seen a situation where there are that many arguments in a single line, so I don't really mind that a line goes beyond the 100 char limit every now and again. However, if there had to be a suggestion of how to format this line, I would say something like this:
|
Beta Was this translation helpful? Give feedback.
-
@bachand I guess in that case we would do what we do with arrays, and live with the oddness of it? |
Beta Was this translation helpful? Give feedback.
-
Yeah, that makes sense too. We usually put an empty line after a guard statement too:
|
Beta Was this translation helpful? Give feedback.
-
I think whatever we come up with should handle long parameter lists too: |
Beta Was this translation helpful? Give feedback.
-
In this case we can convert to |
Beta Was this translation helpful? Give feedback.
-
Consider some code dealing with
Operations
andBlockOperations
that requires the use of a capture list. Generally, capture lists are just[weak self]
, but in this case they're a bit more verbose:This clearly violates the 100 character line rule, so I looked at a few ways of solving:
Problem: the capture list is at the same level of indentation as the code in the block
Problem: same as above, plus the line is still too long
Problem: same as above, but at least there's a space between
in
and the code to be executed. This looks really weird too. Capture lists don't indent like arrays, so the opening and closing brackets are at the same level of indentation as the contents of the capture list.There doesn't seem to be a way to split this into multiple lines cleanly without having the capture list on the same level of indentation as the code, so we need to come up with a "good enough" solution that clearly separates the capture list from the code.
Any thoughts? I'm leaning towards a mix of some of these ideas, but still not super happy with it:
@airbnb/swift-styleguide-maintainers
Beta Was this translation helpful? Give feedback.
All reactions