What is the equivalent of dispatch_block_t in swift?
dispatch_block_t
is a type alias for a Void -> Void
closure. Swift (as of version 1.2) doesn't infer those very well, so you'll need to declare the type. You'll also need to reference self
explicitly to access instance properties, and will want to make sure you're not creating a reference cycle. Declaring self
as weak
in the closure is one safe approach:
let adjustTooltipVisibility: dispatch_block_t = { [weak self] in
if self?._tooltipVisible == true {
self?.tooltipView.alpha = 1
self?.tooltipTipView.alpha = 1
} else {
self?.tooltipView.alpha = 0
self?.tooltipTipView.alpha = 0
}
}