> ## Documentation Index
> Fetch the complete documentation index at: https://docs.syntblaze.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Swift ObjC Members Attribute

The `@objcMembers` attribute is a class-level modifier in Swift that implicitly applies the `@objc` attribute to eligible Objective-C compatible members of a class, its extensions, its subclasses, and all of their extensions. It instructs the compiler to expose these declarations to the Objective-C runtime by generating Objective-C thunks, enabling Objective-C message passing without requiring explicit `@objc` annotations on every individual property, method, or initializer. Crucially, this implicit behavior explicitly excludes members with `private` or `fileprivate` access control.

```swift theme={"dark"}
@objcMembers
class Entity: NSObject {
    var name: String = "" // Implicitly @objc
    func update() {}      // Implicitly @objc
    
    private func internalUpdate() {} // NOT @objc due to access control
    @objc private func tapHandler() {} // Explicitly @objc
}
```

## Dispatch Mechanics

Applying `@objcMembers` (or `@objc`) exposes members to the Objective-C runtime but **does not** alter how Swift dispatches calls to those members. Swift continues to use standard vtable (virtual) or static dispatch for Swift-to-Swift calls. To force dynamic dispatch via Objective-C message passing within Swift (which is required for features like Key-Value Observing or method swizzling), the `dynamic` modifier must be explicitly applied to the specific member.

## Technical Mechanics

When `@objcMembers` is applied to a class, the Swift compiler evaluates every member to determine if it receives the implicit `@objc` attribute based on the following rules:

* **Objective-C Compatibility:** The class itself must inherit from an Objective-C class (typically `NSObject`).
* **Implicit Bridging:** Properties, methods, and initializers utilizing Swift types that bridge to Objective-C (e.g., `String`, `Int`, `Array`, `@objc` protocols) automatically receive the `@objc` attribute.
* **Access Control Exceptions:** The `@objcMembers` attribute explicitly ignores `private` and `fileprivate` members. Even if a private member is Objective-C compatible, it will not receive the implicit `@objc` attribute. If a private member requires Objective-C runtime visibility (such as a target-action method referenced via `#selector`), it must be explicitly annotated with `@objc`.
* **Swift-Exclusive Types:** Members utilizing Swift-only features—such as tuples, generics, structs, or enums with associated values—are strictly incompatible with the Objective-C runtime. The compiler silently ignores these members; they do not receive the implicit `@objc` attribute and remain hidden from Objective-C.

## Inheritance and Extensions

The `@objcMembers` attribute propagates down the inheritance hierarchy and across extensions:

1. **Subclasses:** Any class that inherits from an `@objcMembers` class automatically inherits the `@objcMembers` behavior. All eligible members of the subclass are implicitly exposed to Objective-C.
2. **Extensions:** Members defined within extensions of the annotated class, or extensions of its subclasses, are also implicitly marked as `@objc`.

## Opting Out with `@nonobjc`

Because `@objcMembers` applies a blanket exposure to the Objective-C runtime, it generates Objective-C thunks for all eligible members, which increases the compiled binary size. To override this implicit behavior for specific members, you must use the `@nonobjc` attribute. This explicitly hides the member from the Objective-C runtime.

```swift theme={"dark"}
@objcMembers
class Configuration: NSObject {
    // Implicitly @objc (Exposed to Objective-C runtime)
    var timeout: Double = 30.0
    
    // Implicitly @objc
    func reset() {}
    
    // Ignored by @objcMembers (Tuple is a Swift-only type)
    var metadata: (Int, String) = (0, "none")
    
    // Ignored by @objcMembers due to 'private' access control
    private func calculateHash() {}
    
    // Explicitly @objc despite 'private' access control (e.g., for #selector)
    @objc private func handleTimeout() {}
    
    // Explicitly excluded from Objective-C runtime
    @nonobjc func performInternalRouting() {}
    
    // Explicitly marked dynamic to force Objective-C message passing in Swift
    dynamic func observableMethod() {}
}

// Inherits @objcMembers behavior
class NetworkConfiguration: Configuration {
    // Implicitly @objc
    var endpoint: String = ""
}
```

<div
  style={{ 
display: "flex", 
justifyContent: "space-between", 
alignItems: "center", 
maxWidth: "754px", 
padding: "1rem 0",
marginBottom: "24px"
}}
>
  <span style={{ fontWeight: "bold", fontSize: "1.25rem", color: "var(--tw-prose-headings)", fontFamily: "Inter, ui-sans-serif, system-ui, sans-serif" }}>Tired of Poor Swift Skills? Fix That With Deep Grasping!</span>

  <a
    href="https://syntblaze.com"
    target="_blank"
    style={{ 
  marginLeft: "24px",
  textDecoration: "none", 
  backgroundColor: "#007AFF",
  color: "#ffffff", 
  padding: "6px 16px", 
  borderRadius: "16px",
  fontSize: "0.9rem",
  fontWeight: "600",
  textAlign: "center",
  transition: "background-color 0.2s ease"
}}
  >
    Learn More
  </a>
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/skill-tracking.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=b9b0305c93bb501c9e767b5c76c88835" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/skill-tracking.png" />

  <img src="https://mintcdn.com/syntblazellc/23tyuOzaWS88qFlc/images/nuggets.png?fit=max&auto=format&n=23tyuOzaWS88qFlc&q=85&s=c86c80197299762989e9b882419b2109" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/nuggets.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/bite-sized-exercises.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=a65f9a38c37ff28ab73ed783c53c60e3" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/bite-sized-exercises.png" />
</div>

<div style={{ display: "flex", gap: "12px", flexWrap: "wrap", marginTop: "12px" }}>
  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/mastery-chain.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=748a1763454713e679260fbb95f154a2" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/mastery-chain.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-previews.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=242f61448ff5dd6deaaab2dccc13b507" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-previews.png" />

  <img src="https://mintcdn.com/syntblazellc/-L0ums_2lctDSZ1l/images/element-explanations.png?fit=max&auto=format&n=-L0ums_2lctDSZ1l&q=85&s=cf0fc1c31f9cd0fc26716781be05fbc9" style={{ width: "30%", minWidth: 60 }} width="621" height="1344" data-path="images/element-explanations.png" />
</div>
