#import "ViewController.h"
@interface ViewController ()
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
// 异步加载数据
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
// 模拟数据加载(如网络请求)
NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://example.com/data"]]; // 注意:这只是一个示例,实际上你可能会使用如AFNetworking或URLSession等库
// 解析数据(如JSON)
NSError *error;
NSDictionary *jsonDict = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingMutableContainers error:&error];
// 处理数据...
// 回到主线程更新UI
dispatch_async(dispatch_get_main_queue(), ^{
// 更新UI,例如:
self.label.text = jsonDict[@"someKey"]; // 假设jsonDict有一个key为"someKey"的值
});
});
}
@end