一: 工程图
二: 代码区
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
原文:http://www.cnblogs.com/li625317534/p/5055079.html