6

My code suddenly can't be compiled in Xcode 6.1 (I'm sure it's working in Xcode 6 GM and beta version). It shows the error message:

'NSInvocationOperation' is unavailable

My code is:

let operation = NSInvocationOperation(target:self, selector:"backgroundRun:", object:self)

Can anybody help? Thanks.

1

1 Answer 1

20

As of Xcode 6.1, NSInvocation is disabled in Swift, therefore, NSInvocationOperation is disabled too. See this thread in Developer Forum

Because it's not type-safe or ARC-safe. Even in Objective-C it's very very easy to shoot yourself in the foot trying to use it, especially under ARC. Use closures/blocks instead.

You have to use NSBlockOperation in Swift.

or addOperationWithBlock to NSOperationQueue

queue.addOperationWithBlock { [weak self] in
    self?.backgroundRun(self)
    return
}
2
  • Thanks. I'm using it now.
    – Bagusflyer
    Oct 30, 2014 at 8:40
  • NSInvocation was actually never available in Swift. NSInvocationOperation was only removed in iOS 8.1 SDK.
    – newacct
    Oct 30, 2014 at 19:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.