zoukankan      html  css  js  c++  java
  • Block对象

    我不知道该如何翻译Block这个关键字在Objective-C中,但是可以肯定得是:Block是一段代码。

    我们来看它的英文解释:

    Blocks are a way to define a block of code that you will use at a later time.

    Sometimes people refer to blocks as anonymous functions because they are functions that aren’t
    attached to an entity.

    事实上,Block有点类似我们C#或者Java里的匿名函数。

    来看个例子: 

    eg:

    squareThis = ^(float x){
      return x * x;
    };

    float result = squareThis(4);
    NSLog(@"result = %f", result);

    This will print out the following output to the console log:
    result = 16.000000

    NSString *title = @"Multiply Block Execution";
    float (^multiplyThese)(float, float) = ^(float x, float y)
    {
        NSLog(title);
    
        return x * y;
    };

    NSLog(@"multiplyThese(3,4) = %f", multiplyThese(3,4));

    Output:

    Multiply Block Execution
    multiplyThese(3,4) = 12.000000

  • 相关阅读:
    Light oj 1197
    UVA 11426 GCD
    Light oj 1236
    Light oj 1138
    Light oj 1214-Large Division (同余定理)
    Light oj 1234
    HDU
    ZOJ 3469 Food Delivery(* 区间DP 总结)
    二分查找整理
    zoj 3965 Binary Tree Restoring(* dfs)
  • 原文地址:https://www.cnblogs.com/davidgu/p/3816284.html
Copyright © 2011-2022 走看看