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

4.1k Views Asked by At

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

3

There are 3 best solutions below

2
BadCodeDeveloper On BEST ANSWER

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.

0
gmck On

I had a similar issue: on pasting code from one project to another I suddenly got "CIFormat (aka 'Int32') has no member 'RGBA8'. As the original post states, by jumping to the definition, I could see that 'RGBA8' was defined.

In my case, changing the Swift language version in Build Settings, as per the answer to this question fixed the problem.

The error seems to be due to renaming in the Apple Frameworks that occurred as part of Swift 4.2. Changing the Swift language version to 4.2 resolved the issue.

0
ingconti On

for Xcode 11 / swift 5.1

var backgroundTaskID : UIBackgroundTaskIdentifier = UIBackgroundTaskIdentifier.invalid