能不能實現單獨延遲返回值,不對整個方法造成影響?
-(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
}];