IOS开发(59)之Block Object的调用
2013-05-10 06:50
323 查看
1 前言
本文将介绍如何函数调用Block Object以及Block Object调用Block Object。2 代码实例
TestDemo.h#import <Foundation/Foundation.h> @interface TestDemo : NSObject - (void) callSimpleBlock; - (void) callTrimBlock; @end
TestDemo.m
#import "TestDemo.h" @implementation TestDemo /*************** 方法调用Block Object Start ***************/ void (^simpleBlock)(NSString *) = ^(NSString *paramString){ /* Implement the block object here and use the paramString parameter */ NSLog(@"%@",paramString); }; - (void) callSimpleBlock{ simpleBlock(@"Archy"); } /*************** 方法调用Block Object End ***************/ /*************** Block Object调用Block Object Start ***************/ NSString *(^trimString)(NSString *) = ^(NSString *inputString){ NSString *result = [inputString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]]; return result; }; NSString *(^trimWithOtherBlock)(NSString *) = ^(NSString *inputString){ return trimString(inputString); }; - (void) callTrimBlock{ NSString *trimmedString = trimWithOtherBlock(@" Archy "); NSLog(@"Trimmed string = %@", trimmedString); } /*************** Block Object调用Block Object Start ***************/ @end
main.m
int main(int argc, const char * argv[]) { @autoreleasepool { TestDemo *test = [[TestDemo alloc] init]; // [test callSimpleBlock]; [test callTrimBlock]; } return 0; }
运行结果
2013-05-10 06:53:50.893 CallBlockObjectTest[591:303] Trimmed string = Archy
3 结语
以上就是所有内容,希望对大家有所帮助。Demo下载:http://download.csdn.net/detail/u010013695/5351963
相关文章推荐
- IOS开发(59)之Block Object的调用
- iOS开发之OC与swift开发混编教程,代理的相互调用,block的实现。OC调用Swift中的代理, OC调用Swift中的Block 闭包,swift 3.0
- iOS开发之OC与swift开发混编教程,代理的相互调用,block的实现。OC调用Swift中的代理, OC调用Swift中的Block 闭包,swift 3.0
- 黑马程序员——零基础学习iOS开发——12 Object-C block、protocol
- 如何将C++和Object-C混合编程开发IOS软件(Object-c调用C++)
- IOS开发基础Object-C( 15)-- block的使用方法
- IOS开发ObjectC Block的实现方式
- IOS 开发,调用打电话,发短信,打开网址
- IOS开发笔记12-Object-C中的对象与内存
- IOS开发之──应用之间调用(1)
- ios学习笔记之block在ios开发中的应用
- iOS开发-截获html按钮点击事件,实现js调用native代码
- IOS 开发,调用打电话,发短信,打开网址
- iOS定位服务与地图开发(6)---使用程序外地图之调用谷歌Web地图
- 黑马程序员—(iOS开发)Object-C概述及面向对象---(八)
- [iOS开发]推翻错误结论——“Block可以捕获它的声明所在相同作用域的状态。”
- IOS开发—block对外部变量的内存管理
- iOS开发:StoryBoard 使用Block在两个界面之间传值