func myfunc(i:T) -> T {
return i
}
is it possible to make this generic function a closure?
let myfunc = {
I have found some alternative way , you can use Anyobject in your closure and pass any values to your method .
typealias genericCompletion = ((Bool,T,String) -> Void)
struct Student {
var name:String = "Kishore"
var age : String = "125"
}
class ViewController: UIViewController {
override func viewDidLoad() {
super.viewDidLoad()
self.createAGenericReturn { (success, object, message) in
}
self.createStructGeneric { (success, student, message) in
}
}
func createAGenericReturn(callback:@escaping(genericCompletion)){
callback(true,434.433 as AnyObject,"kishoreTest")
}
func createStructGeneric(callback:@escaping(genericCompletion)){
callback(true,Student.init() as AnyObject,"kishoreTest")
}
}
Here you can see I mentioned Generic as Anyobject typealias genericCompletion = ((Bool,T,String) -> Void) , So you can pass any values to it .