In Swift, protocols with associated types differ fundamentally from generics: associated types allow implementers to choose the concrete type when conforming to the protocol, while generics allow callers to specify the type at the call site. This distinction is crucial because Swift requires associated types to be explicitly declared in the protocol or an inherited protocol, and developers often confuse these two mechanisms when designing protocol-based architectures.
深度探索
先修知识
- 暂无数据。
后续步骤
- 暂无数据。
深度探索
the protocol error every swift dev hits #programming本站添加:
Swift doesn't let you do this.
It says "No dice."
You try to create this protocol and it'll say, "Hey, an associated type named T must be declared in the protocol or in a protocol it inherits." Now, most developers, we try to write code like this and run into this problem. The implementer is providing the type, whereas a generic, like in this case with this generic syntax here, a generic says, "Hey, the caller gets to decide the type."
That's the fundamental difference.
Generics are for the callers to implement and associated types are for the implementers to choose. My take is they're both a variable. It's just who gets to decide what that variable ends up being, the caller or the implementer.
相关推荐
resume fixed instantly 😭 Comment “app”andI’ll sendyou the link #parakeetaipartnership #resumetips
Ritcareer
686 views•2026-05-31
Re: 🗣️📍theprophedu📍2026 GST 103 CLASS (E-EXAM REVISION)
theprophedu
636 views•2026-06-04
3D Basics in C
HirschDaniel
2K views•2026-06-05
Search Algorithms Explained in 60 Seconds! 🤖💨
samarthtuliofficial
218 views•2026-06-01
Making Minecraft Clone with C++ & Raylib
PecaCSLive
686 views•2026-06-04
People of Game of Thrones using JavaScript DOM
AltCampus
296 views•2026-05-30
Instagram accounts got PWNed
EricParker
13K views•2026-06-03
So What's Odin Lang Even Good For
TechOverTea
131 views•2026-06-01











