How to create an array of dispatch_block_t in Swift 2.0?

后端 未结 2 435
北海茫月
北海茫月 2021-01-07 11:52

I have a code in Swift 1.2 to create an array of dispatch_block_t and it works fine. But the same code throws error in Swift 2.0.

var menuView: btSimplePopU         


        
2条回答
  •  清酒与你
    2021-01-07 12:52

    dispatch_block_t is not inherited from AnyObject, it's not object. But you can modify your code and change AnyObject to Any like this:

    andActionArray : actions as [Any]
    

    And it should work for you.

    UPD:

    Your function takes param as NSArray, you can simply cast your array to this type, this code works in my swift playground:

    func pickImages() {}
    func takePicture() {}
    func shootVideo() {}
    
    let actions: [dispatch_block_t] = [{pickImages()},
        {takePicture()},
        {shootVideo()}]
    var actionArray: NSArray = actions as NSArray // pass it to the btSimplePopUP init
    

提交回复
热议问题