定义block块

一: 工程图

二: 代码区

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

 

posted @ 2015-12-17 19:20  li625317534  阅读(172)  评论(0编辑  收藏  举报