oc_study26

来源:互联网 发布:如何申请淘宝介入 编辑:程序博客网 时间:2024/06/05 02:50
main.h
////  main.m//  oc_s26////  Created by sekey on 15/3/19.//  Copyright (c) 2015年 showerli1991. All rights reserved.//#import <Foundation/Foundation.h>#import "Person.h"//int sum(int a, int b)//{//    return a + b;//}//typedef int (^MyBlock) (int, int);int main(void){    Person * p = [[Person alloc] init];        [p test];        //    MyBlock minusBlock = ^(int a, int b)//    {//        return a - b;//    };//    //    MyBlock sunBlock = ^(int a, int b)//    {//        return a + b;//    };//    //    MyBlock multiplyBlock = ^(int a, int b)//    {//        return a * b;//    };//    //    NSLog(@"minusBlock = %i, sunBlock = %i, multiplyBlock = %i", minusBlock(10, 5), sunBlock(5, 5), multiplyBlock(2, 6));//    //                //    int (*p)(int, int) = sum;//    int d = p(11, 13);                //    void (^lineblock)(int) = ^(int n)//    {//        for (int i=0; i<n; i++)//        {//            NSLog(@"-------");//        }//    };//    //    lineblock(3);            //    //    int (^sumblock)(int, int) = ^(int a, int b)//    {//        return a + b;//    };//    //    int c = sumblock(10, 11);//    //    NSLog(@"c = %i", c);//        return 0;}void test(void){    //block    //block sign: ^    /*     block和函数类似     1.可以保存代码     2.有返回值     3.有形参     */        //定义block变量    void (^myblock)(void) = ^{        NSLog(@"block defined");    };    //利用block变量调用bloack代码        myblock();    return;}


Person.h

////  Person.h//  oc_s26////  Created by sekey on 15/3/19.//  Copyright (c) 2015年 showerli1991. All rights reserved.//#import <Foundation/Foundation.h>#import "MyProtocol.h"#import "MyProtocol2.h"@interface Person : NSObject <MyProtocol, MyProtocol2>@end


Person.m

////  Person.m//  oc_s26////  Created by sekey on 15/3/19.//  Copyright (c) 2015年 showerli1991. All rights reserved.//#import "Person.h"@implementation Person- (void)test{    NSLog(@"haha");}- (void)test2{    NSLog(@"test2");}@end


MyProtocol.h

////  MyProtocol.h//  oc_s26////  Created by sekey on 15/3/19.//  Copyright (c) 2015年 showerli1991. All rights reserved.//#import <Foundation/Foundation.h>@protocol MyProtocol <NSObject>- (void)test;- (void)test2;- (void)description;@end


MyProtocol2.h

#import <Foundation/Foundation.h>@protocol MyProtocol2 <NSObject>@end


0 0
原创粉丝点击