使用闭包传值(typealias)

在Swift中使用闭包来实现两个界面的传值

例如:有A类和B类.
B类

//声明闭包
typealias valueBlock = (Float)->()
var returnPrice: valueBlock?


//调用该闭包
self.returnPrice?(price)

A类

let sb = UIStoryboard(name:"Main", bundle: nil)
        
let vc = sb.instantiateViewControllerWithIdentifier("keypadViewVC") as! keypadViewVC
        
//B类的回调
vc.returnPrice = {price in self.gratuityBtn.setTitle(String(format: "%.2f", price), forState:UIControlState.Normal)}
        
self.presentViewController(vc, animated: true, completion: nil)

你可能感兴趣的:(使用闭包传值(typealias))