Сер*_*нич 0 concurrency xcode objective-c grand-central-dispatch
我正在尝试使用SWITCH和GCD加载我的数组,以便不停止主线程.但Xcode无法构建我的代码.请任何人解释一下为什么我可以用这种方式使用GCD?
switch (number) {
case 0:
//case 0:exercise_name="??????";
break;
case 1:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
@synchronized (self.handsMassage){
/*
NSURL* musicFile = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"sound" ofType:@"wav"]];
_click = [[AVAudioPlayer alloc] initWithContentsOfURL:musicFile error:nil];
self.click.delegate = self;
*/
for (int i = 1; i <= 22; i++) {
[self.arrayOfExercise addObject:(id)[UIImage imageNamed:[NSString stringWithFormat:@"ml_%i", i]].CGImage];
}
}
dispatch_async(dispatch_get_main_queue(), ^{
[self.playButton setHidden:NO];
});
});
break;
case 2:
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
@synchronized (self.loinMassage){
/*
NSURL* musicFile = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"sound" ofType:@"wav"]];
_click = [[AVAudioPlayer alloc] initWithContentsOfURL:musicFile error:nil];
self.click.delegate = self;
*/
for (int i = 1; i <= 9; i++) {
[self.arrayOfExercise addObject:(id)[UIImage imageNamed:[NSString stringWithFormat:@"mp_%i", i]].CGImage];
}
}
dispatch_async(dispatch_get_main_queue(), ^{
[self.playButton setHidden:NO];
});
});
break;
Run Code Online (Sandbox Code Playgroud)
XCode打印保护模式下的开关盒?
把{与}周围每一种情况下.像这样:
switch (number) {
case 0:
{
//case 0:exercise_name="??????";
break;
}
case 1:
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
@synchronized (self.handsMassage){
/*
NSURL* musicFile = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"sound" ofType:@"wav"]];
_click = [[AVAudioPlayer alloc] initWithContentsOfURL:musicFile error:nil];
self.click.delegate = self;
*/
for (int i = 1; i <= 22; i++) {
[self.arrayOfExercise addObject:(id)[UIImage imageNamed:[NSString stringWithFormat:@"ml_%i", i]].CGImage];
}
}
dispatch_async(dispatch_get_main_queue(), ^{
[self.playButton setHidden:NO];
});
});
break;
}
case 2:
{
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
@synchronized (self.loinMassage){
/*
NSURL* musicFile = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"sound" ofType:@"wav"]];
_click = [[AVAudioPlayer alloc] initWithContentsOfURL:musicFile error:nil];
self.click.delegate = self;
*/
for (int i = 1; i <= 9; i++) {
[self.arrayOfExercise addObject:(id)[UIImage imageNamed:[NSString stringWithFormat:@"mp_%i", i]].CGImage];
}
}
dispatch_async(dispatch_get_main_queue(), ^{
[self.playButton setHidden:NO];
});
});
break;
}
Run Code Online (Sandbox Code Playgroud)
那应该解决它.
| 归档时间: |
|
| 查看次数: |
571 次 |
| 最近记录: |