Attributes
Attributes should be on their own lines in functions and types, but on the same line as variables and imports
- Identifier: attributes
- Enabled by default: No
- Supports autocorrection: No
- Kind: style
- Analyzer rule: No
- Minimum Swift compiler version: 5.0.0
- Default configuration:
Key Value severity warning attributes_with_arguments_always_on_line_above true always_on_same_line [“@IBAction”, “@NSManaged”] always_on_line_above [] 
Rationale
Erica Sadun says:
My take on things after the poll and after talking directly with a number of developers is this: Placing attributes like
@objc,@testable,@available,@discardableResulton their own lines before a member declaration has become a conventional Swift style.This approach limits declaration length. It allows a member to float below its attribute and supports flush-left access modifiers, so
internal,public, etc appear in the leftmost column. Many developers mix-and-match styles for short Swift attributes like@objc
See https://ericasadun.com/2016/10/02/quick-style-survey/ for discussion.
SwiftLint’s rule requires attributes to be on their own lines for functions and types, but on the same line for variables and imports.
Non Triggering Examples
@objc var x: String
@objc private var x: String
@nonobjc var x: String
@IBOutlet private var label: UILabel
@IBOutlet @objc private var label: UILabel
@NSCopying var name: NSString
@NSManaged var name: String?
@IBInspectable var cornerRadius: CGFloat
@available(iOS 9.0, *)
 let stackView: UIStackView
@NSManaged func addSomeObject(book: SomeObject)
@IBAction func buttonPressed(button: UIButton)
@objc
 @IBAction func buttonPressed(button: UIButton)
@available(iOS 9.0, *)
 func animate(view: UIStackView)
@available(*, deprecated, message: "A message")
 func animate(view: UIStackView)
@nonobjc
 final class X {}
@available(iOS 9.0, *)
 class UIStackView {}
@NSApplicationMain
 class AppDelegate: NSObject, NSApplicationDelegate {}
@UIApplicationMain
 class AppDelegate: NSObject, UIApplicationDelegate {}
@IBDesignable
 class MyCustomView: UIView {}
@testable import SourceKittenFramework
@objc(foo_x)
 var x: String
@available(iOS 9.0, *)
@objc(abc_stackView)
 let stackView: UIStackView
@objc(abc_addSomeObject:)
 @NSManaged func addSomeObject(book: SomeObject)
@objc(ABCThing)
 @available(iOS 9.0, *)
 class Thing {}
class Foo: NSObject {
 override var description: String { return "" }
}
class Foo: NSObject {
 override func setUp() {}
}
@objc
class ⽺ {}
extension Property {
    @available(*, unavailable, renamed: "isOptional")
    public var optional: Bool { fatalError() }
}
@GKInspectable var maxSpeed: Float
@discardableResult
 func a() -> Int
@objc
 @discardableResult
 func a() -> Int
func increase(f: @autoclosure () -> Int) -> Int
func foo(completionHandler: @escaping () -> Void)
private struct DefaultError: Error {}
@testable import foo
private let bar = 1
import XCTest
@testable import DeleteMe
@available (iOS 11.0, *)
class DeleteMeTests: XCTestCase {
}
@objc
internal func foo(identifier: String, completion: @escaping (() -> Void)) {}
@objc
internal func foo(identifier: String, completion: @autoclosure (() -> Bool)) {}
func printBoolOrTrue(_ expression: @autoclosure () throws -> Bool?) rethrows {
  try print(expression() ?? true)
}
import Foundation
class MyClass: NSObject {
  @objc(
    first:
  )
  static func foo(first: String) {}
}
func refreshable(action: @escaping @Sendable () async -> Void) -> some View {
    modifier(RefreshableModifier(action: action))
}
import AppKit
@NSApplicationMain
@MainActor
final class AppDelegate: NSAppDelegate {}
Triggering Examples
@objc
 ↓var x: String
@objc
 ↓var x: String
@objc
 private ↓var x: String
@nonobjc
 ↓var x: String
@IBOutlet
 private ↓var label: UILabel
@IBOutlet
 private ↓var label: UILabel
@NSCopying
 ↓var name: NSString
@NSManaged
 ↓var name: String?
@IBInspectable
 ↓var cornerRadius: CGFloat
@available(iOS 9.0, *) ↓let stackView: UIStackView
@NSManaged
 ↓func addSomeObject(book: SomeObject)
@IBAction
 ↓func buttonPressed(button: UIButton)
@IBAction
 @objc
 ↓func buttonPressed(button: UIButton)
@available(iOS 9.0, *) ↓func animate(view: UIStackView)
@nonobjc final ↓class X {}
@available(iOS 9.0, *) ↓class UIStackView {}
@available(iOS 9.0, *)
 @objc ↓class UIStackView {}
@available(iOS 9.0, *) @objc
 ↓class UIStackView {}
@available(iOS 9.0, *)
 ↓class UIStackView {}
@UIApplicationMain ↓class AppDelegate: NSObject, UIApplicationDelegate {}
@IBDesignable ↓class MyCustomView: UIView {}
@testable
↓import SourceKittenFramework
@testable
↓import SourceKittenFramework
@available(iOS 9.0, *) @objc(abc_stackView)
 ↓let stackView: UIStackView
@objc(abc_addSomeObject:) @NSManaged
 ↓func addSomeObject(book: SomeObject)
@objc(abc_addSomeObject:)
 @NSManaged
 ↓func addSomeObject(book: SomeObject)
@available(iOS 9.0, *)
 @objc(ABCThing) ↓class Thing {}
@GKInspectable
 ↓var maxSpeed: Float
@discardableResult ↓func a() -> Int
@objc
 @discardableResult ↓func a() -> Int
@objc
 @discardableResult
 ↓func a() -> Int
 View on GitHub
            View on GitHub
           Install in Dash
            Install in Dash
          