# Leveraging Swift's 'some' Keyword Beyond SwiftUI

Exploring advanced generic programming techniques in Swift development

- **Source:** [Swift by Sundell (swiftbysundell.com)](https://brifing.si/source/766ea933-99cd-4e7d-ac46-9e01757bf61e)
- **Published:** 2026-09-30
- **Topic:** [Software & Engineering](https://brifing.si/c/engineering)
- **Original article:** <https://www.swiftbysundell.com/articles/using-swifts-some-keyword-beyond-swiftui>
- **On Brifing:** https://brifing.si/s/2f90503a-d0f5-49c7-a664-49e4925a2e49

## SwiftUI's some keyword basics

The 'some' keyword in SwiftUI simplifies view hierarchy declarations by letting the compiler infer concrete types. Without it, developers would need to manually specify complex type signatures for even simple views. This feature becomes particularly valuable when working with SwiftUI's extensive use of generics, eliminating verbose type specifications while maintaining type safety.

## Generic function parameters

Beyond SwiftUI, 'some' can simplify generic function declarations. In a video app example, it replaces complex generic constraints with cleaner syntax while maintaining type safety. The keyword works particularly well with protocols that declare primary associated types, allowing direct protocol references without verbose generic parameter lists.

## Alternative to type erasure

The 'some' keyword provides a compile-time alternative to runtime type erasure patterns. Traditional solutions like 'AnyOperation' wrappers add complexity and overhead. With 'some', developers can hide implementation details while avoiding runtime boxing/unboxing operations, resulting in cleaner APIs without performance penalties.

## API design benefits

Using 'some' enables better encapsulation in public APIs. It allows library authors to keep concrete implementation types private while exposing only protocol requirements. This approach maintains flexibility for future implementation changes without breaking client code, creating more maintainable and evolvable APIs.

## Compile-time resolution

Unlike 'any' which creates runtime existentials, 'some' maintains compile-time type resolution. This means no runtime overhead for type checking or method dispatch. The compiler knows the exact concrete type at compile time, enabling optimizations while providing the abstraction benefits of protocols.

## Protocol requirements

The technique works best with protocols that declare primary associated types using angle bracket syntax. This declaration style enables the compiler to properly infer types when using 'some'. Protocols not designed this way may require manual type annotations or different abstraction approaches.

## Performance considerations

Using 'some' instead of type erasure patterns can improve performance by eliminating runtime indirection. The keyword maintains static dispatch for protocol methods, unlike existential types which require dynamic dispatch. This makes 'some' particularly valuable in performance-critical code paths.

## Future applications

While commonly associated with SwiftUI, 'some' has broader applications in generic Swift programming. As Swift's type system evolves, this keyword will likely play an increasing role in API design patterns. Developers should consider it whenever they need protocol abstraction without runtime overhead.

## Sources covering this story

- https://www.swiftbysundell.com/articles/using-swifts-some-keyword-beyond-swiftui — 

---

_Summary written by Brifing from the original reporting. Copyright in the original article belongs to its publisher; read the full piece at the link above._
