关于block的OC

<main.m>

#import <UIKit/UIKit.h>

#import "AppDelegate.h"

#import "Maxnum.h"


int main(int argc, char * argv[]) {

    @autoreleasepool {

//        return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));

        int num1 = 330;

        int num2 = 98;

        

        int ret;

        

        void (^simpleBlock)(void) = ^{

            NSLog(@"This is a block");

        };

        

        simpleBlock();

        

        int (^mybox)(void) = ^ {

        

            return 100;

        };

        

        int mynum;

        mynum = mybox();

        

        NSLog(@"my num is :%d", mynum);

        

        double (^myarea)(double,double) = ^(double firstvalue, double secondvalue){

            return firstvalue * secondvalue;

        };

        

        double myref = myarea(34,55);

        NSLog(@"myref is :%f",myref);

        

        Big *maxnum = [[Big alloc] init];

        

        ret = [maxnum Max:num1 andNum2:num2];

        

        NSLog(@"my big number is :%d", ret);

        

        return ret;

    };



}


2017-12-05 00:03:51.855979+0800 MyOCtestbc[72326:22235781] This is a block

2017-12-05 00:03:51.857582+0800 MyOCtestbc[72326:22235781] my num is :100

2017-12-05 00:03:51.857887+0800 MyOCtestbc[72326:22235781] myref is :1870.000000

2017-12-05 00:03:51.858448+0800 MyOCtestbc[72326:22235781] my big number is :330


Maxnum.h


#import <Foundation/Foundation.h>


@interface Big:NSObject


- (int)Max :(int)num1 andNum2:(int)num2;



@end


Maxnum.m

#import <Foundation/Foundation.h>

#import "Maxnum.h"


@implementation Big

- (int)Max:(int)num1 andNum2:(int)num2 {

    int result;

    if (num1 > num2) {

        result = num1;

    } else {

        result = num2;

    }

    return result;

}


@end







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值