zoukankan      html  css  js  c++  java
  • Object-C-block

    块是对c语言的一种扩展语法

    块看起来像函数,不同的是,快可以直接写在函数内部

    块能够作为参数传递给函数或者方法

    void sayHello()
    {NSLog(@"hello!");}

    int main()

    {

     //定义一个block

     int i=1;

       void(^sayHello)(void)=^{

        NSLog(@"%d",i) ; // 可以修改快外的东西,不可修改要修改 将i改成 __block i=1;在block 中就可以使用i   

        NSLog(@"hello,i am  a block");  

        };

        sayHello();

        NSString *(^repeat)(NSString *, int )=^(NSString *str,int times){

        NSMutableString *result=[NSMutableString string];  

        for(int i=0; i<times; i++)[result appendString:str];

              return result;

         };

       NSString *string=repeat(@"hello",3);

       return 0;

    }

  • 相关阅读:
    购物网站被p.egou.com强制恶意劫持
    css下拉菜单
    StringToInt
    JframeMaxSize
    frameMaxSize
    inputChar
    英语要求
    sciAndSubject
    fileRename
    tensorflowOnWindows
  • 原文地址:https://www.cnblogs.com/Opaser/p/4554885.html
Copyright © 2011-2022 走看看