This code worked in Swift 2.x:
/// An internal in-memory cache
private var dataCache = NSCache.init()
In Swift 3 it causes compilation error:
Generic parameter 'KeyType' could not be inferred
Why is that so and how should I refactor this (Migration tool did not pick this up)?
NSCache
has been changed to Cache
. NSCache
.Anyway NSCache
is now a generic.
public class NSCache<KeyType : AnyObject, ObjectType : AnyObject> : NSObject { ...
so the most general syntax is
private var dataCache = NSCache<AnyObject, AnyObject>()
The explicit init()
is not needed (not even in Swift 2)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With