Swift 3 NSCache Generic parameter 'KeyType' could not be inferred

后端 未结 1 1852
后悔当初
后悔当初 2021-02-12 17:54

This code worked in Swift 2.x:

/// An internal in-memory cache
private var dataCache = NSCache.init()

In Swift 3 it causes com

1条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-12 18:40

    • In the first Swift 3 betas NSCache has been changed to Cache.
    • In the latest betas (currently 5) it has been reverted to NSCache.

    Anyway NSCache is now a generic.

    public class NSCache : NSObject { ...
    

    so the most general syntax is

    private var dataCache = NSCache()
    

    The explicit init() is not needed (not even in Swift 2)

    0 讨论(0)
提交回复
热议问题