I came across this problem several times when porting Objective-C code to Swift. Let's say I have the following code:
dispatch_async(dispatch_get_main_queue()) { self.hostViewController?.view.addSubview(self.commandField) }
This will result in an error underlining the entire dispatch_async call, suggesting:
Could not find member 'addSubview'
I assume this is an error that has not yet been properly implemented, because if I put the addSubview call outside the dispatch_async block, the project will be obstinate. Initially, I assumed that this might have something to do with capturing self in a block. However, inserting [unowned self] in leads to the same error as [weak self] in (after the corresponding spread operators were inserted ! ).
How can I get dispatch_async blocks to work in Swift that need to capture self ?
swift grand-central-dispatch
Ephemera Jun 07 '14 at 1:29 2014-06-07 01:29
source share