How to Implement resident threads in AFN and resident threads in AFN
The underlying implementation of the nsunloop is actually an endless loop of do-while at the underlying layer.
Method 1:
-(Void) viewDidLoad {[super viewDidLoad]; _ thread = [[CXThread alloc] initWithTarget: self selector: @ selector (run) object: nil]; [_ thread start];}-(void) run {NSLog (@ "run -- xubao loves fish"); // Add a Real-Time Port listener [[nsunloop currentRunLoop] addPort: [NSPort port] forMode: NSDefaultRunLoopMode]; // Add runloop [[[nsunloop currentRunLoop] run];}-(void) test {NSLog (@ "test -- xubao loves fish % @", [NSThread currentThread]);}-(void) touchesBegan :( NSSet
*) Touches withEvent :( UIEvent *) event {// Let the test Method Implement [self defined mselector: @ selector (test) onThread: self. thread withObject: nil waitUntilDone: NO];}
Method 2:
-(Void) viewDidLoad {[super viewDidLoad]; _ thread = [[CXThread alloc] initWithTarget: self selector: @ selector (run) object: nil]; [_ thread start];}-(void) run {NSLog (@ "run -- xubao loves fish"); while (1) {// Add runloop [[[nsunloop currentRunLoop] run] ;}}- (void) test {NSLog (@ "test -- xubao loves fish % @", [NSThread currentThread]);}-(void) touchesBegan :( NSSet
*) Touches withEvent :( UIEvent *) event {// Let the test Method Implement [self defined mselector: @ selector (test) onThread: self. thread withObject: nil waitUntilDone: NO];}