1

I am working on a project that up to now, despite the mess, it was working ok. Today, believe it or not, I have been updating it to Swift 5.

The project has iOS and tvOS targets as well as frameworks, tests, and top selves extensions. The project also was started using Objective-C and over the years has become 90% Swift.

I am not sure at what point something went wrong but, when compiling, I get the following error for all my top self extensions (mostly all tvOS Targets).

enter image description here

I have found similar questions but I can't understand whats going on.

Any ideas?

Reimond Hill
  • 4,278
  • 40
  • 52

2 Answers2

1

You are probably missing an import StoreKit in the Swift files that define IAPHelper. Sometimes this gets imported transitively, and Swift doesn't necessarily need it, but the Swift bridging header does.

Ultimately you need to make sure there's an ObjC @import StoreKit; that is evaluated before this line of code.

Rob Napier
  • 286,113
  • 34
  • 456
  • 610
  • Thank Rob for your reply. IAPHelper.swift has already 'import StoreKit' Where should I be adding '@import StoreKit' – Reimond Hill Jun 03 '20 at 17:56
  • @ReimondHill at the top of the header where it is used – Max Jun 03 '20 at 17:57
  • I mean the ObjC @import StoreKit; My IAPHelper class is swift but overrides from NSObject – Reimond Hill Jun 03 '20 at 18:02
  • In principle you could add `@import StoreKit;` before `#import <...-Swift.h>` in every file, but that shouldn't be necessary. (Similarly you could put it in the pch file, but again, that's just hacking around the problem.) First, make sure to remove everything in DerviedData and build again. And make sure you've added StoreKit to your linked frameworks list. – Rob Napier Jun 03 '20 at 18:26
  • I've seen this problem before; I'm just trying to remember if there was anything tricky about fixing it. – Rob Napier Jun 03 '20 at 18:27
  • Isn’t there a potential issue with the order of imports? I can’t remember the details either... – matt Jun 03 '20 at 20:03
  • Maybe… I do import `-Swift.h` last generally, in the `.m` file rather than the `.h` file (but not always, so I'm not certain about that). – Rob Napier Jun 03 '20 at 21:38
0

First, I have to thank Rob for his tips. I wish he could get the points!

After troubleshooting with the tips provided:

  • Add StoreKit to your linked frameworks list. -> Didn't work
  • @import StoreKit; before #import <...-Swift.h> -> Showed error use of @import when modules are disabled

I also saw that "...-Swift.h" was only declared in the Build settings of my "...Topself" targets. Still quite unsure why as I would have thought the whole project still have ObjC dependencies... Still quite new to this challenge.

Furthermore, If I unfold the error I could see that there was some kind of error trying to find "...-Swift.h" file.

At this point, I remembered that I am using cocoapods (I don't like you, you don't like me relationship) and I hated to see the warning "...Overrides Enable modules (C - Objective-C)" so I set it to default for the whole project.

Turns out that that for all "...TopSelf" targets, the default value is NO.

By Overriding Enable modules (C - Objective-C) to YES, clean, and build, everything started working again.

Reimond Hill
  • 4,278
  • 40
  • 52
  • In my case, it was complaining about `AuthenticationServices`framework, so I added #import in the bridging header file and it solved the issue. – dev gr Aug 17 '22 at 09:11