Using as a concrete type conforming to protocol AnyObject is not supported

前端 未结 6 1335
时光取名叫无心
时光取名叫无心 2020-12-05 00:12

I\'m using Swift 2 and using WeakContainer as a way to store a set of weak objects, much like NSHashTable.weakObjectsHashTable()

struct WeakCont         


        
6条回答
  •  醉酒成梦
    2020-12-05 01:00

    Why are you trying to use generics? I would suggest doing the following:

    import Foundation
    import UIKit
    
    protocol MyDelegate : AnyObject {
    
    }
    
    class WeakContainer : AnyObject {
        weak var value: MyDelegate?
    }
    
    class ViewController: UIViewController {
        var delegates = [WeakContainer]()
    }
    

    There is also NSValue's nonretainedObject

提交回复
热议问题