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

2019-08-04 14:54发布

问题:

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.