xcode10ios12swift4.2uibackgroundtaskios-background-mode

Swift4.2 Type 'UIBackgroundTaskIdentifier' (aka 'Int') has no member 'invalid'


I'm getting a weird issue where code which works in one XCode project fails to compile in another. Both run Swift4.2.

Why do I get "UIBackgroundTaskIdentifier has no member 'invalid' error?

import UIKit import Foundation

//Type 'UIBackgroundTaskIdentifier' (aka 'Int') has no member 'invalid'
var backgroundTask: UIBackgroundTaskIdentifier = UIBackgroundTaskIdentifier.invalid

I can jump into the UIBackgroundTaskIdentifier definition and see this: enter image description here


Solution

  • I had the same problem. Solved using UIBackgroundTaskInvalid instead of .invalid

    var backgroundTask: UIBackgroundTaskIdentifier = UIBackgroundTaskInvalid

    Not sure why it acts so strange. In the example from raywenderlich.com code compiles without errors.