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:
    KeyValue
    severity warning
    attributes_with_arguments_always_on_line_above true
    always_on_same_line [“@IBAction”, “@NSManaged”]
    always_on_line_above []

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