Block object call for iOS development (59)

Source: Internet
Author: User
1 Preface

This article describes how to call block object by using functions and how to call block object by using block object.

2. code example

Testdemo. h

#import <Foundation/Foundation.h>@interface TestDemo : NSObject- (void) callSimpleBlock;- (void) callTrimBlock;@end

Testdemo. m

# Import "testdemo. H "@ implementation testdemo/**************** method to call block object start ************** */void (^ simpleblock) (nsstring *) = ^ (nsstring * paramstring) {/* implement the block object here and use the paramstring parameter */nslog (@ "% @", paramstring );}; -(void) callsimpleblock {simpleblock (@ "Archy ");} ***************//** * ************ block object call block object start ******************/nsstring * (^ trimstring) (nsstring *) = ^ (nsstring * inputstring) {nsstring * result = [inputstring character: [nscharacterset whitespacecharacterset]; return result ;}; nsstring * (^ trimwithotherblock) (nsstring *) = ^ (nsstring * inputstring) {return trimstring (inputstring) ;};-(void) calltrimblock {nsstring * trimmedstring = trimwithotherblock (@ "Archy "); nslog (@ "Trimmed string = % @", trimmedstring );} /*************** block object call block object start *****************/@ end

Main. m

int main(int argc, const char * argv[]){    @autoreleasepool {                TestDemo *test = [[TestDemo alloc] init];//        [test callSimpleBlock];        [test callTrimBlock];    }    return 0;}

Running result

06:53:50. 893 callblockobjecttest [591: 303] trimmed string = Archy

3 conclusion

The above is all content and I hope it will help you.

Demo download: http://download.csdn.net/detail/u010013695/5351963

Related Article

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.