Block生命周期
2016-02-24 13:09
337 查看
#import <UIKit/UIKit.h> typedef NSString*(^MyBlock) (NSString*,NSInteger); @interface ViewController : UIViewController -(MyBlock)GetDefaltBlock:(NSString*)Astr withInt:(NSInteger) Aint; @end
#import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; MyBlock _b = [self GetDefaltBlock:@"Hello" withInt:123]; NSLog(@"%@",_b(@"World",456)); } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; } -(MyBlock)GetDefaltBlock:(NSString *)Astr withInt:(NSInteger)Aint { MyBlock b = ^NSString*(NSString* Bstr, NSInteger Bint) { return [NSString stringWithFormat:@"STR IS %@,INT IS %ld", [Astr stringByAppendingString:Bstr],Aint + Bint]; }; return b; } @end
这个居然也能行,不可思议啊,一直以为访问不到astr运行的时候会有错误。
arc环境下,还挺神奇。
非arc环境参考http://bbs.9ria.com/thread-259515-1-1.html
相关文章推荐
- java.io.StreamCorruptedException: invalid stream header报错原因
- 21、微信 - 主界面布局
- MySQL 清除表空间碎片
- windows8运行php Composer出现SSL报错的问题
- 算法导论—最长公共子序列
- 修该hosts访问谷歌
- 轻松解决listView数据混乱
- php正则验证手机号码
- 如何用手机拍好一个女生
- 了解Linux的基础知识和一般概念
- iOS 拦截系统自带的Pop事件
- leetcode笔记--Length of Last Word
- Laravel输出JSON时设定输出字段的几种情况总结
- Git安装和使用
- 字符数组,字符串指针
- .NET中SQL Server数据库连接方法
- ActiveMQ系列(1) - 使用入门
- 浅谈Java中的接口和抽象类
- 微信从无到有
- 调查问卷