Skip to content

Instantly share code, notes, and snippets.

@mdznr
Last active August 29, 2015 14:02
Show Gist options
  • Save mdznr/941e9271585effdb8d9a to your computer and use it in GitHub Desktop.
Save mdznr/941e9271585effdb8d9a to your computer and use it in GitHub Desktop.
How do you best align function calls on multiple lines?
// In Objective-C, a relatively long method call could be easily wrapped on multiple lines:
[attributedString addAttribute:NSParagraphStyleAttributeName
value:paragraphStyle
range:NSMakeRange(0, attributedString.length)];
// But how do you do that in Swift?
attributedString.addAttribute(NSParagraphStyleAttributeName, value: paragraphStyle, range: NSRange(location: 0, length: attributedString.length))
// This is the closest I can get, but it's still pretty ugly.
attributedString.addAttribute(NSParagraphStyleAttributeName,
value:paragraphStyle,
range:NSRange(location:0, length:attributedString.length))
@ArtSabintsev
Copy link

Apple just does it straight out in one line in their UIVIewController class:

    // Custom containers should override this method and search their children for an action handler (using -canPerformUnwindSegueAction:fromViewController:sender:). If a handler is found, the controller should return it. Otherwise, the result of invoking super's implementation should be returned.
    func viewControllerForUnwindSegueAction(action: Selector, fromViewController: UIViewController!, withSender sender: AnyObject!) -> UIViewController!

@ethnt
Copy link

ethnt commented Jun 5, 2014

This is how I generally deal with super long method calls in Ruby, not sure how well it carries over to Swift:

attributedString.addAttribute(
  NSParagraphStyleAttributeName,
  value:paragraphStyle
  range:NSRange(
    location:0,
    length:attributedString.length
  )
)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment