Common Attributes in Swift
From the Swift cheat sheet · Attributes · verified Jul 2026
Common Attributes
Built-in Swift attributes
swift
// @available for API availability
@available(iOS 15.0, macOS 12.0, *)
func newFeature() {
print("This requires iOS 15+")
}
@available(*, deprecated, message: "Use newMethod instead")
func oldMethod() {
print("This method is deprecated")
}
// @objc for Objective-C interop
@objc class MyClass: NSObject {
@objc dynamic var name: String = ""
@objc func doSomething() {
print("Callable from Objective-C")
}
}
// @discardableResult
@discardableResult
func configure() -> Bool {
// Setup code
return true
}
configure() // No warning about unused result
// @escaping for closures
func performAsync(completion: @escaping () -> Void) {
DispatchQueue.main.async {
completion()
}
}💡 @available helps manage API compatibility across OS versions
⚡ @objc enables Objective-C interoperability
📌 @escaping marks closures that outlive the function
🟢 @main designates the app entry point