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
import XCPlayground
XCPlaygroundPage.currentPage.needsIndefiniteExecution = false
import Foundation
let a: dispatch_block_t = {
print("a")
}
let b: dispatch_block_t = {
print("b")
}
let arr = [a,b]
print(arr.dynamicType)
arr.forEach { (b) -> () in
b()
}
/* prints
Array<@convention(block) () -> ()>
a
b
*/
class Block {
var block: dispatch_block_t
init(block: dispatch_block_t){
self.block = block
}
}
let block1 = Block(block: a)
let block2 = Block(block: b)
let arr2: NSArray = [block1,block2]
print(arr2)
arr2.forEach { (p) -> () in
(p as? Block)?.block()
}
/* prints
(
Block,
Block
)
a
b
*/