Skip to content

Swift

Native Regex since v1.0

๐Ÿฆ… Catches public and open declarations. Collapses multiple public inits into a single init symbol per type.

.swift

What gets detected

The public surface spec-sync tracks for Swift.

  • public / open func, class, struct, enum, protocol, actor
  • public / open var, let, typealias
  • public init(...) (tracked as 'init')

Detection rules

public and open declarations

Both public (accessible within the module and to importers) and open (subclassable/overridable) are captured. Handles static and class modifiers.

public class AuthService {}
public struct Config {}
public enum AuthStatus { case active, expired }
public protocol Authenticator {}
public typealias Token = String
open class BaseController {}
public actor SessionManager {}

Public properties and functions

Matches public var/let and public func (including public static func).

public var token: String
public let apiVersion: Int
public func validate() -> Bool {}
public static func shared() -> AuthService {}

Public initializers

public init and public convenience init are collapsed to a single 'init' symbol in the output.

public init(name: String) {}
public convenience init() {}

Example: spec & source

The *.spec.md contract on the left, the Swift source it documents on the right. spec-sync matches the two.

Spec (*.spec.md)

---
module: auth
version: 1
status: stable
files:
  - Sources/Auth/AuthService.swift
---

## Purpose

Provides JWT authentication for the app layer.

## Public API

| Symbol | Kind | Description |
|--------|------|-------------|
| `AuthService` | class | Main auth service |
| `validate` | func | Validates a token |
| `AuthStatus` | enum | Active or expired states |
| `Authenticator` | protocol | Auth contract |

## Change Log

| Date | Change |
|------|--------|
| 2026-01-01 | Initial |

Source

public class AuthService {
    public var token: String
    public init(token: String) { self.token = token }
    public func validate() -> Bool { return !token.isEmpty }
}

public enum AuthStatus { case active, expired }
public protocol Authenticator { func authenticate() -> Bool }

Test-file patterns

Files matching these are excluded from the detected surface.

Pattern Explanation
**/*Tests.swift XCTest test class files: auto-excluded
**/*Test.swift Alternate test naming: auto-excluded

Caveats

  • internal, fileprivate, and private declarations are excluded. Only public and open are captured.
  • Swift property wrappers (@Published, @State, etc.) are captured by the underlying var/let declaration.
  • Extension members with public access are captured if the extension itself is in a public declaration context.
  • Macro-generated public symbols are not detected.

Related languages