美文网首页iOSIMiOS 面试题
Swift 学习之写一个属性 闭包函数(block) 和协议(代

Swift 学习之写一个属性 闭包函数(block) 和协议(代

作者: 马爷 | 来源:发表于2016-10-26 11:34 被阅读22次

闭包函数(block)
<pre>
//闭包函数(block) 声明
var timeBlockSelect : (NSString, NSString) -> () = {a, b in return}
</pre>

<pre>
//闭包函数(block) 调用
self.timeBlockSelect(self.startTime as NSString, self.endTime as NSString)
</pre>

协议(代理)
<pre>
//协议(代理)
protocol TFPickerDelegate :NSObjectProtocol{
func PickerSelectorIndixString(string:NSString);
func PickerSelectIndixColor(color:UIColor);
}
</pre>

<pre>
//协议(代理)声明

//添加代理属性
weak var delegate:TFPickerDelegate?
</pre>

<pre>
//协议(代理) 调用

self.delegate?.PickerSelectorIndixString(string: fullStr)
</pre>

<pre>
//协议(代理) 添加
swiftChoiseView.delegate = self
//添加代理方法
class SwiftTimeSelectViewController: UIViewController,UITableViewDelegate, UITableViewDataSource, TFPickerDelegate {}
</pre>

<pre>
//协议(代理) 实现
func PickerSelectorIndixString(string: NSString) {
print("daili")
}

func PickerSelectIndixColor(color: UIColor) {
   print("xieyi")
}

</pre>

相关文章

网友评论

    本文标题:Swift 学习之写一个属性 闭包函数(block) 和协议(代

    本文链接:https://www.haomeiwen.com/subject/ogpduttx.html