Swift naming conventions for ivars (properties)

639 views Asked by At
class MainWindowController: NSWindowController, NSSplitViewDelegate {

@IBOutlet var splitView: NSSplitView!

override func windowDidLoad() {
  splitView.setPosition(lastSplitViewPosition, ofDividerAtIndex: 0)
}

func splitView(splitView: NSSplitView!, canCollapseSubview subview: NSView!) -> Bool {
  return subview == splitView.subviews[0] as NSView
}

What is the naming convention in Swift for the NSSplitView outlet? If I call it splitView as above it is irritating as the splitView in windowDidLoad is the property (I could also write it as self.splitView) and the one in the delegate method is the argument of splitView:canCollapseSubview:

Options I can think of:

  • Always use self.splitView for the property
  • Name the property differently
  • Name the argument in the delegate method differently (ugly...)
1

There are 1 answers

0
Tone416 On BEST ANSWER

The convention in Swift is to name properties and parameters as clearly as possible without worrying about this situation. Use self. to distinguish between them only when necessary. Apple uses this convention in the iBook The Swift Programming Language, especially for initializers.