iOS Question

MapleBacon.DiskStorage no longer granting access to images after 3.0.0 upgrade: why?

Following the documentation at https://github.com/zalando/MapleBacon, I created the following, which was working in Swift 2.3:

import MapleBacon

fileprivate let
_manager: ImageManager
, _storage: DiskStorage
, _stopwatch: Stopwatch
, _urlsLoading: [ String ]

required init ()
{
_manager = ImageManager.sharedManager
_storage = DiskStorage( name: "MyStorageName" )
_stopwatch = Stopwatch()
_urlsLoading = []
}

func loadImageBy ( Url url: String )
{
guard let nsurl = URL( string: url ) else { return }

_urlsLoading.append( url )

_manager.downloadImage(
atUrl: nsurl
, cacheScaled: true
, imageView: nil
, storage: _storage
, completion:
{
[ unowned self ] ( image, error ) -> Void in
self._stopwatch.startWith(
Delay: 0.02
, ForListener: self._onStopwatchComplete
)
}
)
}


I found that using my own
Stopwatch
component to force a delay of 0.02 enabled
MapleBacon.DiskStorage
to make the images available via its
image( forKey: )
method:

fileprivate lazy var _onStopwatchComplete: ( String, Any? ) -> Void =
{
[ unowned self ] ( key: String, data: Any? ) -> Void in

var url: String, imageCount = 0

// loop through urls of images being loaded
for _ in 0..<self._urlsLoading.count
{
url = self._urlsLoading[ imageCount ]

// image found
if let img = self._storage.image( forKey: url )
{
print( img )
// remove from list of urls of images being loaded and...
self._urlsLoading.remove( at: imageCount )
}

// image not found: continue waiting
else
{
imageCount += 1
}
}

self._stopwatch.stop()
}


With the Swift 3.0 version of MapleBacon though, even a delay of 5 seconds is not producing a reference to the image in
_storage
, and just like the Swift 2.3 version, does not have it in the
completion: ( image, error ) ->
closure either.

With the
3.0.0
version of
MapleBacon
, what does one need to do to successfully both store and retrieve images from
DiskManager
, please?

Thank you [for reading, at least].

PS: I do not have the required score to create a
MapleBacon
tag. If anyone does and can, that would be great, thank you.

Answer

Jan Gorman, a contributor to MapleBacon, identified this as a genuine bug, and uploaded a fix for it (issue trail here: https://github.com/zalando/MapleBacon/issues/38). The code that worked in Swift 2.3 now also works in Swift 3.0.