我在IBAction中有下面的代碼。我想測量AVSpeechSynthesizer在指令列表中運行的確切時間。但是,executionTime會立即記錄下來,而不是在循環結束時(返回時間少於1秒,而不是我預期的10-15秒)。我做錯了什麼?NSLog立即執行而不是循環結束
NSDate *methodStart = [NSDate date];
for (NSString* direction in directions) {
AVSpeechUtterance *aDirection = [[AVSpeechUtterance alloc] initWithString:direction];
aDirection.rate = .3;
[self.synthesizer speakUtterance:aDirection];
}
NSDate *methodFinish = [NSDate date];
NSTimeInterval executionTime = [methodFinish timeIntervalSinceDate:methodStart];
NSLog(@"executionTime = %f", executionTime);
此委託將爲每個'AVSpeechUtterance'調用一次,所以你也必須算調用僅在最後打印的時候,或者你可以有多個日誌條目,只關心最後一個。 –
開始iOS程序員仍然在努力瞭解如何使用代表,但這給了我一個方向。謝謝! – babyjordan