【发布时间】:2014-12-11 11:12:55
【问题描述】:
在我的小型 iOS 应用程序中,我有一个表示直方图的 CSV 文件。文件内容为:
标签0,值0
...
标签N,值N
在我的 ViewController 中,我以这种方式与 Grand Central Dispatch 异步读取文件:
//create the channel with which read the CSV file
dispatch_io_t ch = dispatch_io_create_with_path(DISPATCH_IO_STREAM, [[[NSBundle mainBundle] pathForResource:@"histogram1" ofType:@"csv"] UTF8String], O_RDONLY, 0, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(int error) {
if(!error){
NSLog(@"Channel created!");
}
});
//read the whole file
dispatch_io_read(ch, 0, SIZE_MAX, dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^(bool done, dispatch_data_t dataRead, int error) {
if(!error && done){
NSString *ma = ; //???
NSLog(@"%@", ma);
}
});
我想将dataRead(dispatch_data_t 类型)转换为NSString,以提取代表直方图条形的值。
【问题讨论】:
标签: ios objective-c csv asynchronous grand-central-dispatch