Variable in generic class cannot be represented in objective c
Trying to create a generic ViewControlelr that uses the model type and handles pagination etc. Getting the following error. Is there a workaround for this?
Variable in a generic class cannot be represented in Objective-C
class BasePaginatingViewController<T: BaseModel>: UIViewController {
@IBOutlet var tableView: UITableView!
}
+3
source to share
1 answer
No, there are no generics in Objective-C unless you want to use C ++ templates, which are very discouraging.
The closest you can get in Objective-C is passed as "id" and then confirms if the type of object you recognize is one of the following:
if([o respondsToSelector:@selector(myMethod)]) {
[o myMethod];
if([o conformsToProtocol:@protocol(MyProtocol)]) {
[o myMethod];
if ([o isKindOfClass:MyClass.class]) {
// do something.
}
But if you really want to do this ... Follow this:
0
source to share