0

I have a MacOS project with several targets and in which I have been refactoring Obj-C classes over to Swift 1 by 1. I have been doing this for months and all was fine and building well until the most recent class. The project simply refuses to build.

I see the ProjectName-Swift.h file in the Project folder but the last was build date was last week and obviously does not include the new class, hence Xcode is complaining it can't find the new Swift Class.

Before you answer understand the following:

  • This is a very old and longstanding MacOS project with several targets, it is NOT a new MacOS project.
  • I have previously added quite a few other Swift classes to this project and built and used them just fine in Obj-C .m files including the one that is complaining it can't see the latest Swift class: ChartListTableCellView.
  • I already tried clean and build about 50 times and removing derived data. Nothing will force a rebuild of the ProjectName-Swift.h and the new class is definitely NOT in there.
  • There are no other build issues with this just this one related to not being able to see the class.
  • The class was previously implemented in Obj-C and I was porting it over and that old class file is not referenced by the project at the moment.
  • This Swift class ChartListTableCellView is NOT referenced in the obj.h file so it is not forward referenced there.
  • The Bridge Header is imported in the .m that is complaining.

The project will not build and does not see the new class. This is how the class is declared so it should be visible:

@objcMembers class ChartListTableCellView : NSView
{
    private let grayBottomBorder = NSView()
    ...

    init() {
        super.init(frame: NSMakeRect(0, 0, 0, 0))
        ...
    }
    ...
 }

I am stumped and am out of ideas.

Cliff Ribaudo
  • 8,932
  • 2
  • 55
  • 78
  • 1
    How did you remove derived data? – wcochran Jul 03 '23 at 14:38
  • Got there via Xcode Settings -> Locations -> Dervied data which opened in Finder and deleted the folder. – Cliff Ribaudo Jul 03 '23 at 14:49
  • Do you have a minimal project that manifests the issue? That may be why the dv… seems like a legit question to me. – wcochran Jul 03 '23 at 22:26
  • @wcochran my friend, if you read the question carefully you would probably see that I mentioned in the 1st bullet, that this is not a new project. It is quite old, with several targets and has other Swift classes already integrated with it and working fine with Obj-C code.... so I am not really sure I understand your question or point. The project was working just fine BEFORE I added this class. – Cliff Ribaudo Jul 04 '23 at 11:41
  • 1
    Try quit XCode/relaunch, reboot the Mac. Sometimes it can solves these "cache" silly issues. Try to rename your class maybe, with a prefix to see if it fixes it. – Larme Jul 04 '23 at 11:44
  • @Larme done the quit/restart blah blah thing, didn't help. Why would renaming the class fix it? The issue seems to be that it does not build ProjectName-Swift.h until late in the Build process ... which seems kind of backAssWards, and I can't get to that stage because it is complaining in the Obj-C file that the class does not exist. Even tried pulling the old .h file into the Obj-C.m to see if I could get it to build the Bridge Header.. but nope. Xcode really needs a way to force build that file. Lot of people run into this. – Cliff Ribaudo Jul 04 '23 at 11:53
  • 1
    Remove/comment the occurence of that classes in Objective-C code, and rebuilt? – Larme Jul 04 '23 at 14:06
  • Interesting ... guess I can try that. – Cliff Ribaudo Jul 04 '23 at 14:14
  • Well tried it, but no luck. Still not building the ProjectName-Swift.h. Tried changing the Build Setting to $(SRCROOT)/$(SWIFT_MODULE_NAME)-Swift.h just to see what happens and I get a weird error that I can't find any data on .. invalid task SwiftMergeGeneratedHeaders – Cliff Ribaudo Jul 04 '23 at 14:29

1 Answers1

0

The solution to this turned out to be shockingly EZ:

  1. delete/rename the old ProjectName-Swift.h and if the project is properly configured, Xcode will spot it and instantly rebuild a new one! I had avoided touching this file because a lot of SO posts said NEVER delete it. Being desperate I renamed it and Xcode instantly spotted it was missing and generated a new one without the issue?!

  2. Another issue was that the Project Build settings was incorrect. I had recently changed the Objective-C Generated Interface Header Name:

    To -> $(SRCROOT)/$(SWIFT_MODULE_NAME)-Swift.h

    From -> $(SWIFT_MODULE_NAME)-Swift.h

That was baaaad. Don't do it. This change may have caused it to stop updating the Bridge Header file. I had thought it was a PATH and wanted to "future proof" the setting in case the project moved. But it doesn't want a PATH here, just a file name, just use: $(SWIFT_MODULE_NAME)-Swift.h.

Cliff Ribaudo
  • 8,932
  • 2
  • 55
  • 78
  • "I saw a lot of other SO posts saying NEVER delete it" You're using git, so a way back is always there. – Larme Jul 04 '23 at 15:02