Is it true Xcode/IB DOES NOT check for protocols?

一曲冷凌霜 提交于 2019-12-11 06:55:52

问题


Xcode5 milieu only. (Not older versions.)

1) make a new class called say Test. it's a UIViewController

@interface Test:UIViewController

2) in storyboard, make a new screen, a UIViewController, change it to "Test"

obviously, if you add a control (say, a button) on the storyboard, you can drag it to an IBOutlet defined in Test.h. No problem.

3) Now in Test.h add the two protocols ..

@interface Test:UIViewController
          <
          UICollectionViewDataSource,
          UICollectionViewDelegateFlowLayout
          >

4) now in IB drag a small UICollectionView in to the view.

5) click on the collection view, connections inspector. now, drag the delegate and dataSource to "Test"

Everything works correctly .. no problem.

However. Disconnect those connections. Go back to step (3). Do not do step 3. in other words, you've "forgotten" to add the protocols to Test.

Now try step (5)

In fact (I believe) ... it works fine.

It seems strange to me that you can drag to a UICollectionViewDataSource (say) when, in fact, it simply is NOT a UICollectionViewDataSource (!)

(Naturally, you can't drag, say, a button anywhere there is no IBOutlet.)

(A) Does everyone else see this behaviour, of have I screwed up as usual?

(B) Is this perhaps a known bug / omission?

(C) Is there anything else I'm missing ("oh, it has to be like that because...")

Cheers


回答1:


Yes, it's true. UIB does not check any protocol method is implemented. Even if you enabled warnings for Incomplete Objective-C Protocols in Build Settings for your project, its behaviour is the same.



来源:https://stackoverflow.com/questions/22786858/is-it-true-xcode-ib-does-not-check-for-protocols

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!