Basic Syntax of Objective-C: nsunloop

Source: Internet
Author: User

Directly add the code without explanation.

1 #import <Foundation/Foundation.h>2 3 @interface Demo01 : NSObject4 5 6 -(void) run;7 -(void) start;8 9 @end
1 # import "demo01.h" 2 3 @ implementation demo01 4 5-(void) run 6 {7 static int counter = 0; 8 9 While (! [[Nsthread currentthread] iscancelled]) {10 [nsthread sleepfortimeinterval: 1]; 11 nslog (@ "Current Value: % I", counter ++ ); 12} 13 14} 15 16-(void) start17 {18 [nsthread detachnewthreadselector: @ selector (run) totarget: Self withobject: Nil]; 19} 20 21 @ end
 1 #import <Foundation/Foundation.h> 2 #import "Demo01.h" 3  4 int main(int argc, const char * argv[]) 5 { 6  7     @autoreleasepool { 8          9         // insert code here...10         NSLog(@"Hello, World!");11         12         [[[Demo01 alloc] init]start];13         14         while (YES) {15             16             [[NSRunLoop currentRunLoop]runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];17         }18         19     }20     return 0;21 }

 

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.