How to make a class conform to a protocol in Swift?

前端 未结 3 1563
没有蜡笔的小新
没有蜡笔的小新 2020-12-08 03:29

in Objective-C:

@interface CustomDataSource : NSObject 

@end

in Swift:

class CustomDataSource         


        
3条回答
  •  星月不相逢
    2020-12-08 04:13

    Type 'CellDatasDataSource' does not conform to protocol 'NSObjectProtocol'

    You have to make your class inherit from NSObject to conform to the NSObjectProtocol. Vanilla Swift classes do not. But many parts of UIKit expect NSObjects.

    class CustomDataSource : NSObject, UITableViewDataSource {
    
    }
    

    But this:

    Type 'CellDatasDataSource' does not conform to protocol 'UITableViewDataSource'

    Is expected. You will get the error until your class implements all required methods of the protocol.

    So get coding :)

提交回复
热议问题