[崩溃日志]Simultaneous accesses to 0x28261ebd0, but

今天遇到原本没问题的项目在播放音频后报错:

Simultaneous accesses to 0x28261ebd0, but modification requires exclusive access. Previous access (a

屏幕快照 2019-06-21 上午10.42.03.png

原因是结构体需要同时进行读写操作导致线程不安全

代码如下:

sound.requestSound(success: { (url) in
     self.startPlayRecord(path: url)
     sound.isPlaying = true          // 1
     tempChat.type = .sound(sound)   // 2
}, failure: {
      ChatManager.shared.chats[index] = tempChat
})

修改后

var mySound = sound
var myTempChat = tempChat
sound.requestSound(success: { (url) in
       self.startPlayRecord(path: url)
       mySound.isPlaying = true          // 1
       myTempChat.type = .sound(mySound)   // 2
 }, failure: {
        ChatManager.shared.chats[index] = myTempChat
})

你可能感兴趣的:([崩溃日志]Simultaneous accesses to 0x28261ebd0, but)