Using LTRunLoop you can just deliver your pending data,which needs to be handled on a secondary thread by the the method you provide,then LTRunLoop help you create a secondary thread and run the run loop of the thread to dispatch your data via input source.Finally,the run loop will invoke your method to handle the data,as an argument passed in,which you had delivered.LTRunLoop let you focus on input and hanlers of data.
[[LTRunLoopManager manager] start];
Using an object to handle the data
the object should confirm the protocol
LTRunLoopSourceHandler.
id data = [NSString stringWithFormat:@"success test send a LTRunLoopTask\n%d",++self.count];
LTSourceTask *task = [LTSourceTask getASourceTaskWithPeddingData:data
sourceHandler:anObject];
[[LTRunLoopManager manager] addSourceTask:task];
Or Using a class to handle the data
, but the class must confirm the protocol
LTRunLoopSourceHandler.
static int count = 0;
id data = [NSString stringWithFormat:@"success test send a LTRunLoopTask\n%d",++count];
LTSourceTask *task = [LTSourceTask sourceTaskWithPeddingData:data
sourceHandlerClassName:NSStringFromClass(LTViewController.class)
completion:^(LTSourceData *sourceData){
// code you want to execute in the call back...
}];];
[[LTRunLoopManager manager] addSourceTask:task];
RunLoopSourceHandler.h
declare two methods as follow:
- (void)object_runLoopSourceHandled:(LTSourceData *)sourceData;
+ (void)class_runLoopSourceHandled:(LTSourceData *)sourceData;
To run the example project, clone the repo, and run pod install
from the Example directory first.
LTRunLoop is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'LTRunLoop'
panyult, litaoxiwang@163.com
LTRunLoop is available under the MIT license. See the LICENSE file for more info.