daltoniam / Skeets

Fetch, cache, and display images via HTTP in Swift.
Apache License 2.0
191 stars 21 forks source link

Sometimes get error while loading images for the first time #4

Closed mahmed8003 closed 9 years ago

mahmed8003 commented 9 years ago
if self.pending[hash] == nil {
            var holder = Array<BlockHolder>()
            holder.append(BlockHolder(progress: progress, success: success, failure: failure))
            self.pending[hash] = holder
            //next check from disk asynchronously
            cache.fromDisk(hash, success: { (d: NSData) in
                self.doSuccess(hash, data: d)
                }, failure: { (Void) in
                    //lastly fetch from the network asynchronously
                    let task = HTTPTask()
                    task.download(url, parameters: nil, progress: { (status: Double) in
                        self.doProgress(hash, status: status)
                        }, success: { (response: HTTPResponse) in
                            self.cache.add(hash, url: response.responseObject! as NSURL)
                            self.doSuccess(hash, data: self.cache.fromMemory(hash)!)
                        }, failure: { (error: NSError, response: HTTPResponse?) in
                            self.doFailure(hash, error: error)
                    })
            })
        } else if var array = self.pending[hash] {
            array.append(BlockHolder(progress: progress, success: success, failure: failure))
            self.pending[hash] = array
        }

Getting error: fatal error: unexpectedly found nil while unwrapping an Optional value at line self.doSuccess(hash, data: self.cache.fromMemory(hash)!)

daltoniam commented 9 years ago

Could you please verify if response.responseObject or self.cache.fromMemory(hash) is nil? That would help narrow down what is going wrong.

daltoniam commented 9 years ago

Where you able to verify which one is nil?

mahmed8003 commented 9 years ago

I found self.cache.fromMemory(hash) is nil

screen shot 2015-01-24 at 3 54 40 am

daltoniam commented 9 years ago

Thanks. Interesting that it is coming back nil. I am investigating now.

daltoniam commented 9 years ago

I just checked in a fix, let me know if that resolves the issue.

daltoniam commented 9 years ago

Where you able to verify the fix worked?

daltoniam commented 9 years ago

I'm going to assume this is now resolved with the latest code. Thanks for the report and help.