Tapping on a tableview cell segue you to another view. Once arriving on that other view I call a webservice to load data asynchronously.
As I wish to keep my cell class clear from network code, I want to define my webservice call in the TableViewController, and set a kind of delegate property of my TableViewCell on prepareForSegue().
///TableViewController
override func prepareForSegue(...) {
dest = TableViewCell
dest.getDataDelegate = getData
}
func getData(...) -> X? {
...
}
///TableViewCell
var getProductDelegate: ((...) -> X?)!
override func viewWillAppear() {
...
getProductDelegate(...) //Error - Cannot call value of non function type
}
If I get ride of the parenthesis around the type declaration of getData, it recognize it as a function, but then the class needs initializer. I am using storyboard so I wish to avoid it.
Thanks in advance!
Edit: I guess I just have to unwrap it if it's optionnal
Edit2: Yhea, stupid error. My bad, posting answer
Ok, as it's optionnal, the property type getProductDelegate is not a function anymore.
A simple unwrap allow you to use it as a function, as usual:
if let func = getProductDelegate {
func(...)
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.