mzeeshanid / MZDownloadManager

This download manager uses NSURLSession api to download files. It can download multiple files at a time. It can download large files if app is in background. It can resume downloads if app was quit.
BSD 3-Clause "New" or "Revised" License
1.12k stars 238 forks source link

Index out of range #40

Open AnasMostefaoui opened 7 years ago

AnasMostefaoui commented 7 years ago

Hello

Trying to download 2 objects at the same time, an out of range exception is thrown caused by this line : 208 : self.downloadingArray[index] = downloadModel

file : MZDownloadManager.swift

look likes a race condition, since the object may be removed befor the code above is executed, which lead to that exception.

to fix this issue, I changed to previous line with the following :

 if self.downloadingArray.contains(downloadModel), let objectIndex = self.downloadingArray.index(of: downloadModel) {

                        self.downloadingArray[objectIndex] = downloadModel

                    }