我是新手。我正在使用Grand Central Dispatch在另一個線程上填充數組(student_temp)。那部分工作正常。問題是我無法將數組傳遞給類屬性(student_Array),並在整個類中使用它。我無法在主線程上重新獲取數組。如何從Grand Central Dispatch獲取數組?
它工作正常,直到我回到他的主線程,我無法將student_temp傳遞到student_array(屬性)內部或外部的GCD。
我在做什麼錯,還是有更好的使用GCD填充數組屬性?
謝謝你的幫助。如果可能的話,請嘗試用非技術性的語言來解釋我是新手。
- (void)viewDidLoad
{
[super viewDidLoad];
R2LFetcher *studentFetch = [[R2LFetcher alloc] init];
__block NSMutableArray *student_temp = [[NSMutableArray alloc] init];
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0ul);
dispatch_async(queue, ^{
//long-running code goes here…
student_temp = [studentFetch fetchToStudentArray];
dispatch_async(dispatch_get_main_queue(), ^{
// code the updates the main thread (UI) here...
student_Array = student_temp;
});
});
student_Array = student_temp;
是什麼student_Array – codercat