Declare “NSMapTable StrongObject” in Swift 3

前端 未结 1 1921
耶瑟儿~
耶瑟儿~ 2021-01-22 18:43

How can I declare an NSMapTable in Swift 3? Why doesn\'t this example from Apple work?

let activeLines = NSMapTable.strongToStrongObjectsMapTable()
         


        
1条回答
  •  南笙
    南笙 (楼主)
    2021-01-22 19:40

    NSMapTable.strongToStrongObjects() will fail with the error:

    error: generic parameter 'KeyType' could not be inferred
    NSMapTable.strongToStrongObjects()
               ^
    

    The class declaration of NSMapTable is:

    open class NSMapTable : NSObject, NSCopying, NSCoding, NSFastEnumeration
    

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

    NSMapTable.strongToStrongObjects()
    

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