feat:add iOS listview

This commit is contained in:
pengfei.zhou
2019-11-15 19:30:07 +08:00
parent 6017e7120d
commit 8e53e4b54b
11 changed files with 230 additions and 15 deletions

View File

@@ -43,6 +43,8 @@ typedef void(^DoricFinishCallback)(void);
- (BOOL)hasResult;
- (R)getResult;
- (R)waitUntilResult;
@end
NS_ASSUME_NONNULL_END

View File

@@ -22,31 +22,32 @@
#import "DoricAsyncResult.h"
@interface DoricAsyncResult()
@property(nonatomic,strong) id result;
@interface DoricAsyncResult ()
@property(nonatomic, strong) id result;
@end
@implementation DoricAsyncResult
- (void)setupResult:(id)result {
self.result = result;
if(self.resultCallback){
if (self.resultCallback) {
self.resultCallback(result);
}
if(self.finishCallback){
if (self.finishCallback) {
self.finishCallback();
}
}
- (void)setupError:(NSException *)exception {
self.result = exception;
if(self.exceptionCallback){
if (self.exceptionCallback) {
self.exceptionCallback(exception);
}
if(self.finishCallback){
if (self.finishCallback) {
self.finishCallback();
}
}
- (BOOL)hasResult {
return self.result;
}
@@ -57,22 +58,35 @@ - (id)getResult {
- (void)setResultCallback:(DoricResultCallback)callback {
_resultCallback = callback;
if(self.result && ![self.result isKindOfClass: [NSException class]]){
if (self.result && ![self.result isKindOfClass:[NSException class]]) {
callback(self.result);
}
}
- (void)setExceptionCallback:(DoricExceptionCallback)exceptionCallback {
_exceptionCallback = exceptionCallback;
if([self.result isKindOfClass: [NSException class]]){
if ([self.result isKindOfClass:[NSException class]]) {
exceptionCallback(self.result);
}
}
- (void)setFinishCallback:(DoricFinishCallback)callback {
_finishCallback = callback;
if(self.result){
if (self.result) {
callback();
}
}
- (id)waitUntilResult {
if (self.result) {
return self.result;
}
dispatch_semaphore_t semaphore = dispatch_semaphore_create(0);
self.resultCallback = ^(id r) {
dispatch_semaphore_signal(semaphore);
};
dispatch_semaphore_wait(semaphore, DISPATCH_TIME_FOREVER);
return self.result;
}
@end