Axcel Kuhn Axcel Kuhn - 1 year ago 145
Swift Question

Declare "NSMapTable StrongObject" in Swift 3

How can I declare an

in Swift 3? Why doesn't this example from Apple work?

let activeLines = NSMapTable.strongToStrongObjectsMapTable()

Xcode suggested change to:

let activeLines = NSMapTable.strongToStrongObjects()

but it still does not work.

I need convert this example to Swift 3

Answer Source

NSMapTable.strongToStrongObjects() will fail with the error:

error: generic parameter 'KeyType' could not be inferred

The class declaration of NSMapTable is:

open class NSMapTable<KeyType : AnyObject, ObjectType : AnyObject> : NSObject, NSCopying, NSCoding, NSFastEnumeration

You need to specify the key and object types of your map table in its declaration:

NSMapTable<NSObject, NSObject>.strongToStrongObjects()
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download