今天在寫 delegate
(@protocol
) 要檢查 delegate method 有沒有被實作,結果 Xcode 抱怨:
1
|
|
respondsToSelector:
這個 method 是未知的。
讓自訂 Protocol 遵循 NSObject Protocol
因為之前在寫 protocol 的時候都太順了。後來發現是在 @protocol 宣告的地方:
1 2 3 4 5 |
|
沒有讓 protocol conform to NSObject
protocol 。因此在宣告的時候加上 <NSObject>
就可以了:
1 2 3 4 5 |
|
而 respondsToSelector:
是屬於 NSObject
protocol ,所以要是要讓自己的 protocol 能夠使用這些檢查用的 methods ,就要加上去。