in Objective-C:
@interface CustomDataSource : NSObject <UITableViewDataSource>
@end
in Swift:
class CustomDataSource : UITableViewDataSource {
}
However, an error message will appear:
What should be the correct way ?
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 NSObject
s.
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 :)