Protocol
只宣告可以做什麼,但沒有定義怎麼做,遵從 protocol 代表會有 protocol 的能力, protocol 型別不能直接建立資料, class, struct, enum 的型別才能建立資料
Question.
protocol 下定義的function , class 下可以除了繼承原先protocol 的function 外, 還可定義其他不同的 function ?為什麼變數 handsomeMan 已經定義成Man 卻無法繼承 class下的 cry function?
Answer.
因為型別宣告成 Idol ,所以只能使用 Idol 裡宣告的 sing()
Get Yun Chu Wang’s stories in your inbox
Join Medium for free to get updates from this writer.
class 除了遵從protocol,擁有protocol的function, 也可宣告其他的function ,但下面的變數都不能用protocol 以外的function ,除了真的把 handsomeMan變成Man 才可以執行Man宣告的function.



![[心得] iOS Human Interface Guidelines](https://miro.medium.com/v2/resize:fit:1358/format:webp/0*9HjzffxC56m6tw47.png)





