Swift 3 NSCache Generic parameter 'KeyType' could not be inferred
- In the first Swift 3 betas
NSCache
has been changed toCache
. - In the latest betas (currently 5) it has been reverted to
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)
Initializing a Struct in Swift Error: Generic parameter could not be inferred
For a generic type, the generic parameter is actually considered to be part of the type. So the type of your struct isn't MyStruct
, it's MyStruct<Int>
(or whatever generic type you use. Therefore, you can't just declare the type by itself if there's not any information for the compiler to use to infer the actual type. Instead, you have to include the generic type in your declaration:
var myStruct: MyStruct<Int>?
Generic type 'Result' specialized with too few type parameters (got 1, but expected 2)
You can qualify the reference to Result in order to choose the one you want. The version with one parameter belongs to Alamofire. The one with two parameters belongs to Swift.
typealias Response<T> = (_ result: Alamofire.Result<T>) -> Void
... or ...
static func upload(
data: Data,
completion: @escaping (Swift.Result<Int, Error>) -> Void
)
Related Topics
Swift Core Data Sync with Web Server
Passing Data Between View Controllers Without Segue
Avmutablevideocomposition Output Video Shrinked
Traverse View Controller Hierarchy in Swift
Swift 3 - Nsfetchrequest Distinct Results
Swift Scenekit - Centering Scntext - the Getboundingboxmin:Max Issue
Skspritenode Subclassing Swift
Get Progress of Uinavigationcontroller Swipe Back
Avcapturesession and Avaudiosession Recording Video While Background Music Playing Only Works Once
Setting Custom Http Headers in Alamofire in iOS 7 Not Working
Using Haneke to Cache Then Play Mp4 Files with Avplayer
How to Bridge Nsnumber to Float in JSON Parsing
How to Execute a Function in a Uiviewcontroller Through a Swiftui Button
iOS Swift 2 Record Video Avcapturesession
Custom Uitoolbar Too Close to the Home Indicator on iPhone X
Skspritenode Does Not Let Touches Pass Through When Isuserinteractionenabled False
How to Trigger an API Call Before Displaying Local Notifications