https://developer.apple.com/videos/play/wwdc2022/110352/
<aside> π λͺ©μ°¨
[x] μ°μ νλ² λ£κΈ°
[ ] Opaque νμ μ΄ λ¬΄μμΈμ§ λͺ ννκ² μ μλ΄λ¦΄ μ μλκ°? - μ΄κ±΄ λ΄λλ΄λ μ΄λ ΅λ€
some
, underlying type, concrete typeprotocol Animal {
associatedtype Feed: AnimalFeed
func eat(_ food: Feed)
}
struct Farm {
// μλ νν λλ€ κ°λ₯
func feed<A: Animal>(_ animal: A) { ... }
func feed<A>(_ animal: A) where A: Animal
}
type parameter
μ where
λ₯Ό ν΅ν΄ 볡μ‘ν μꡬμ¬νμ νμ
κ΄κ³λ₯Ό ννν μ μλ€.
μλ ννμ μμ£Ό μ¬μ©λλ ννμΈλ°, A κ° λ°λ³΅ λ±μ₯νμ¬ μ‘°κΈ λ³΅μ‘ν΄λ³΄μΈλ€.
some
μ μ¬μ©νλ©΄ μ ννκ³Ό λμΌνμ§λ§ μ’λ κ°λ¨νκ² ννν μ μλ€.