能不能实现单独延迟返回值,不对整个方法造成影响?
-(CGFloat)getValue{
// code implementation
return floatvalue; // return float value with some delay.
}
能不能实现单独延迟返回值,不对整个方法造成影响?
-(CGFloat)getValue{
// code implementation
return floatvalue; // return float value with some delay.
}
使用block回调值时延迟
- (void)ayncGetValue:(void(^)(id value))returnBlock {
dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 10.f * NSEC_PER_SEC); // delay 10 seconds
dispatch_after(popTime, dispatch_get_main_queue(), ^{
returnBlock(@"hello block");
});
}
// Usage
[obj ayncGetValue:^(id value) {
// continue
}];