I know the title of the question is not correct for the question. But I could not come up with better title, Ill modify if somebody suggests a better title.
Here is the question:
I have a protocol,
import Foundation
protocol MyFilter {
var currentlySelected : Bool { get set }
func configure<T> (filterInfo : T) where T: MyGenericDataModel
}
This asks all the confirming classes to declare a variable named currentlySelected and also expects to write a method that takes a single parameter that confirms to MyGenericDataModel protocol.
MyGenericDataModel looks like,
import Foundation
protocol MyGenericDataModel {
init(data : JSON)
}
There are multiple classes that confirms to MyGenericDataModel. Like,
struct MyDataModel1 : MyGenericDataModel {
var id : String? = nil
//other properties
init(data : JSON) {
}
}
struct MyDataModel2 : MyGenericDataModel {
var id : String? = nil
//other properties
init(data : JSON) {
}
}
and so on.
Now I get the array of data which can be any of the custom data model. So I declared a array of objects which confirms to MyGenericDataModel protocol.
var passedDataSource: Array< MyGenericDataModel>? = nil
Now I need to call the method of MyFilter,
let filterInfo = passedDataSource![indexPath.row]
abcd.configure(filterInfo: filterInfoToPass)
Where abcd obviously confirms to MyFilter thats why I can call configure on it.
Issue
Xcode gives compilation error saying,
Can not invoke 'configure' with an argument list of type '(filterInfo: MyGenericDataModel)
EDIT:
As per luk2302's comment, I am posting the implementation details of class of abcd :)
class MyCellClass: UICollectionViewCell, MyFilter{
var currentlySelected : Bool = false
func configure<T>(filterInfo: T) where T : MyGenericDataModel {
//use filter info
//perform some UI operations to update cell UI
}
}
Please help. Thanks in advance.