首页 > 其他 > 详细

定义block块

时间:2015-12-17 20:45:32      阅读:262      评论:0      收藏:0      [点我收藏+]

一: 工程图

技术分享

二: 代码区

AppDelegate.h

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (retain, nonatomic) UIWindow *window;

//@property (strong, nonatomic) UIWindow *window;

@end

AppDelegate.m

#import "AppDelegate.h"

@interface AppDelegate ()

@end

#pragma mark - 定义有返有参block块并重命名
typedef int (^SUM)(int , int);

#pragma mark - 定义无返无参block块并重命名
typedef void (^LOVE)();

@implementation AppDelegate
- (void)dealloc
{
    self.window = nil;
    
    [super dealloc];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
    // Override point for customization after application launch.
    
#pragma mark - 有返有参block块调用方法
    SUM sum1 = ^(int a , int b) {
        
        return a + b;
    };
    
    NSLog(@"%d" , sum1(5 , 10));
    
    
#pragma mark - 有返有参block块调用方法
    LOVE love = ^() {
        
        NSLog(@"I Love You!");
    };
    
    love();
    
    self.window.backgroundColor = [UIColor whiteColor];
    [self.window makeKeyAndVisible];
    return YES;
}

@end

 

定义block块

原文:http://www.cnblogs.com/li625317534/p/5055079.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!