Review of Block

Source: Internet
Author: User

Main.m

//

Main.m

8a10. Review of Block

//

Created by Huan on 16/2/8.

copyright©2016 year Huanxi. All rights reserved.

//

#import <Foundation/Foundation.h>

function Definition

void Test () {

}

int sum (int A, int b) {

return A + b;

}

int Main (int argc, const Char * argv[]) {

@autoreleasepool {

//Insert code here ...

// review block

// What is a block on a chunk of code

What is the difference between a//block and a function

//1. functions can only be defined outside the method

//2.block can be defined within a method or can be defined outside of a method

//3.block and functions in common: all have return values and parameters

//block definition

// no return value no parameter block

void(^testblock) () = ^{

NSLog(@ " no return value no parameter block");

};

Testblock ();

// no return value for block with parameters

void(^test2block) (int) = ^ (int a) {

NSLog(@ " you are passing in %d", a);

};

Test2block (2);

// has a return value, the block with parameters

int(^sumblock) (int,int) = ^ (int A,int b) {

return A + b;

};

int result = Sumblock (2,3);

NSLog(@ " through block calculation, the result is:%d", "result");

// with return value, blcok with no parameters

//block to redefine typedef

typedef void (^mtestblock) ();

//For Blcok with no return value, no parameters - custom

mtestblock mtestblcok = ^ () {

NSLog(@ "redefined block");

};

Mtestblcok ();

// define a special operation for Blcok

typedef void (^operationblock) ();

operationblock operationblock = ^ () {

NSLog(@ " Checking for version updates ");

};

Operationblock ();

NSLog(@ "Hello, world!" );

}

return 0;

}

Results

Review of Block

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.