any
這個新的關鍵字是對使用 "existential types" 的一種「標示」,或可說是「警示」:
// ⭐️ it's OK for now (Swift: < 6.0 ✅, >= 6.0 ❌)
let a: SomeProtocol
// ⭐️ 'any' is required in Swift 6.0
let a: any SomeProtocolthe any keyword simply annotates that a given type is a so-called existential ... existentials are relatively expensive to use because the compiler and runtime can’t pre-determine how much memory should be allocated for the concrete object that will fill in the existential ... the cost of using existential types should not be hidden, and programmers should explicitly opt into these semantics.
👉 Donny ⟩ What is the “any” keyword in Swift?
Swift ⟩ Swift 5.6 Released!
compare: some (opaque type) (🗝️ some)
Last updated
Was this helpful?