4

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

Alex Stone
  • 46,408
  • 55
  • 231
  • 407
  • Can't reproduce with Xcode 10.1 and Swift 4.2. – Tamás Sengel Dec 08 '18 at 13:35
  • I'm seeing the behavior within two different projects open in the same version of XCode. The example from https://www.raywenderlich.com/5817-background-modes-tutorial-getting-started works, but when carried over into my project with apple watch, it gives the error. – Alex Stone Dec 09 '18 at 10:48
  • I have same problem on Xcode 10.1 and Swift 4.0. – Borzh Feb 17 '19 at 15:01

3 Answers3

11

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.

BadCodeDeveloper
  • 455
  • 5
  • 24
  • 1
    You should file a bug report with Apple. Something’s wrong here. – matt Dec 28 '18 at 08:15
  • I wish Apple would work on the compiler error messages, especially in the context of the ever changing Swift language, – brainray Mar 25 '19 at 20:15
2

for Xcode 11 / swift 5.1

var backgroundTaskID : UIBackgroundTaskIdentifier = UIBackgroundTaskIdentifier.invalid
ingconti
  • 10,876
  • 3
  • 61
  • 48
0

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.

gmck
  • 1