OC的 block的写法:
https://www.jianshu.com/p/1457a4894ec7
返回值类型 (^block的名称) (block的参数)=^(参数列表){
//执行的代码
};
//例子
int (^sumOfNumbers)(int a , int b)=^(int a,int b){
/*下面为代码块*/
return a + b;
};
调用 NSLog(@"块返回:%d",myBlockC(1,5));
Swift的 闭包 的写法:
返回值类型:
{
(形参) -> (返回值类型) in
// 执行代码
}
let hero = {
(firstName:String,lastName:String,age:Int)->(String,Int) in
/*下面为代码块*/
let info:String = "名称:" + firstName + " 字: " + lastName + "\n" + "终年:" + String(age);
return (info,age);
}
调用: let b = hero("诸葛亮","孔明",56);