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 }