Private Outlets

IBOutlets should be private to avoid leaking UIKit to higher layers

  • Identifier: private_outlet
  • Enabled by default: No
  • Supports autocorrection: No
  • Kind: lint
  • Analyzer rule: No
  • Minimum Swift compiler version: 5.0.0
  • Default configuration:
    KeyValue
    severity warning
    allow_private_set false

Non Triggering Examples

class Foo { @IBOutlet private var label: UILabel? }
class Foo { @IBOutlet private var label: UILabel! }
class Foo { var notAnOutlet: UILabel }
class Foo { @IBOutlet weak private var label: UILabel? }
class Foo { @IBOutlet private weak var label: UILabel? }
class Foo { @IBOutlet fileprivate weak var label: UILabel? }
//
// allow_private_set: true
//

class Foo { @IBOutlet private(set) var label: UILabel? }

//
// allow_private_set: true
//

class Foo { @IBOutlet private(set) var label: UILabel! }

//
// allow_private_set: true
//

class Foo { @IBOutlet weak private(set) var label: UILabel? }

//
// allow_private_set: true
//

class Foo { @IBOutlet private(set) weak var label: UILabel? }

//
// allow_private_set: true
//

class Foo { @IBOutlet fileprivate(set) weak var label: UILabel? }

Triggering Examples

class Foo { @IBOutlet var label: UILabel? }
class Foo { @IBOutlet var label: UILabel! }
class Foo { @IBOutlet private(set) var label: UILabel? }
class Foo { @IBOutlet fileprivate(set) var label: UILabel? }