Skip to content

About

This project demonstrates how to use Swift’s `@frozen` and `@inlinable` attributes in a practical and ABI-safe way. These annotations are especially useful when designing **public APIs** in Swift frameworks and libraries.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

4 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

🧊 InlinableAndFrozenEnum

A practical Swift package demonstrating how to use @frozen and @inlinable attributes to write stable and high-performance public APIs.

These annotations are critical for library developers who care about ABI stability, performance optimization, and clean module interfaces.


📦 Overview

✅ @frozen

Marks a public enum or struct as layout-stable. Once frozen:

  • New cases/properties cannot be added.
  • Enables exhaustive switch statements in external modules without @unknown default.
  • Helps the compiler optimize memory and dispatch.

✅ @inlinable

Marks a function or computed property as inlinable across module boundaries. This allows:

  • Clients to see and compile the body of the function.
  • The compiler to apply inline optimizations.
  • Reduced call overhead in performance-sensitive APIs.

📁 Structure

InlinableAndFrozenEnum/ ├── README.md ├── PaymentResult.swift /// @frozen enum └── MessageHelper.swift /// @inlinable function

🛠 When to Use

Scenario Use @frozen Use @inlinable
Building a public enum with fixed cases ✅ ❌
Struct with known and stable layout ✅ ❌
Public helper method needing performance ❌ ✅
Exposing implementation to other modules ❌ ✅

📚 Learn More

Here are some official Swift resources to deepen your understanding of @frozen, @inlinable, and ABI stability:

About

This project demonstrates how to use Swift’s `@frozen` and `@inlinable` attributes in a practical and ABI-safe way. These annotations are especially useful when designing **public APIs** in Swift frameworks and libraries.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages