iOS更新14.4.2后Swift中的列表操作问题



几年来,我使用这个简单的代码来读取和操作Swift:中的列表

if (Helper.hasSubscription()) {

self.allVisitedTrackHandles = Database.getAllCompletedTrackHandles(withDeleted: false, userid: self.userid)

if (self.allVisitedTrackHandles.count > 0) {

var counter = 0

for th: TrackHandle in self.allTrackHandles {

if self.allVisitedTrackHandles.contains(where: { $0.trackid == th.trackid }) {

for thv: TrackHandle in self.allVisitedTrackHandles {

if thv.trackid == th.trackid {

self.allTrackHandles[counter].date_in_milliseconds = thv.date_in_milliseconds

break
}

}

self.allTrackHandles[counter].visited = 1

}


counter += 1

}
}
}

在将我的iOS设备更新到iOS 14.4.2后,应用程序在以下行崩溃:

for th: TrackHandle in self.allTrackHandles

Xcode给我的唯一反馈是:线程79:EXC_BAD_ACCESS(代码=1,地址=0x12f100010(

我不知道为什么那条线会突然崩溃;所显示的代码中没有任何内容会导致崩溃。你在其他地方更新数组吗?这可能是线程问题吗?

您可以重构此代码,使其更简单、更清晰、更高效。这可能会有所帮助;

if Helper.hasSubscription() {
self.allVisitedTrackHandles = Database.getAllCompletedTrackHandles(withDeleted: false, userid: self.userid)
if !self.allVisitedTrackHandles.isEmpty {

for index in 0..<self.allTrackHandles.count {
if let visited = self.allVisitedTrackHandles.first { $0.track id == self.allTrackHandles[index].track id } {
self.allTrackHandles[index].date_in_milliseconds = visited.date_in_milliseconds
}
self.allTrackHandles[index].visited = 1                        
}
}    
}

相关内容

  • 没有找到相关文章

最新更新