0

I have created a swift package that compiled fine.

I have imported the swift package in a project.

No class inside the package is seen on the project. So I made them public.

I added public init() {} where needed.

Methods are still not seen.

So I modify code in the package from within the project, but Xcode does not compile the package or check any errors. So, I do not see any errors in the package.

Thus, I have to close the project, open the package to see the errors, do and test the modifications, close the package, open the project.

This is necessary because Xcode will not allow to see the package if the project using it is opened.

For duck's sake, that is annoying as hell.

Is there a way to compile and debug the package from within the project? Without this insanity of closing one and opening the other?

Changing the package from Xcode's top bar, does nothing.

And why the public classes and methods inside the package are still not seen on the project? Is there something I have to add to the manifest?

My manifest is the one created by default by Xcode. The package has no dependencies and is just a collection of classes and class extensions I created over the years.

In resume: I have a "package" and a "project" that depends on the package (as a local Swift package). When I open the project, the errors in the package are not being reported and the classes are not public, even after they have been declared as so (I've added this comment by Sweeper to clarify things).

Duck
  • 34,902
  • 47
  • 248
  • 470
  • exactly! Very annoying. – Duck Aug 09 '23 at 09:19
  • Did you add tests to the package to ensure everything is working first, before using it in a project? If you did, you wouldn't have needed to "compile and debug the package from within the project". Also, showing your Package.swift files can probably help with finding out why the public classes are not visible. – Sweeper Aug 09 '23 at 09:20
  • and also the classes and functions declared as public are still not seen in the project. – Duck Aug 09 '23 at 09:22
  • what do you mean by `showing your Package.swift files can probably help with finding out why the public classes are not visible`? showing here? – Duck Aug 09 '23 at 09:23
  • ok, just a sec! – Duck Aug 09 '23 at 09:24
  • I assume you did `import` your module before using it? And remember to also add the package to "Frameworks, Libraries, and Embedded Content" if you haven't. – Sweeper Aug 09 '23 at 09:30
  • Yes, I did both. I am modifying the question with the code... – Duck Aug 09 '23 at 09:33
  • Can you show screenshots of your project navigator? To locally embed and edit a package, you drag the containing folder into the project, under the main project. If you've also added it via package dependency, Xcode is smart enough to use the local one. – jrturton Aug 09 '23 at 09:38
  • I have modified the question with the requested code. – Duck Aug 09 '23 at 09:39
  • I have added it by using **File > Add Packages > Add Local**, browsed to where the package is and voilà. – Duck Aug 09 '23 at 09:42
  • I am removing the code. After dealing with it, it now works. But my error persists – Duck Aug 09 '23 at 09:53

2 Answers2

1

Adding a package using the method you've described doesn't seem to perform the final step of adding it to the target. If you do that (in Frameworks, Libraries and Embedded Content in the general settings for the target), it works. Though I confess I had to kick Xcode a couple of times to get it to stop complaining.

jrturton
  • 118,105
  • 32
  • 252
  • 268
  • thanks for your help. Xcode is so bad that it crashes constantly if I, for example, rename a file inside a package and packages sometimes are imported like crap. Thanks. – Duck Aug 09 '23 at 10:31
0

I love Xcode. The answer to solve this was to remove the package from the project and add it again.

Duck
  • 34,902
  • 47
  • 248
  • 470
  • When you drop the _folder_ of a package into Xcode's _Project Navigator_, it becomes a _local package_. Note that dependencies of this package will be added into the "Package Dependencies" section. Usually, you use this "local" style when _developing_ the package. When the version is done, you push it to a git repo, delete the local package _reference_ from Xcode and then add it as a _Package Dependency_ with Xcode. If you have _both_, a remote package dependency and a local package, the local package gets precedence. You need to get familiar with this concept. Try it out! ;) – CouchDeveloper Aug 09 '23 at 10:40
  • Note also, a local package can be opened only once in one Xcode project. So, if you use it in several, you must close one project. Can be confusing at times. – CouchDeveloper Aug 09 '23 at 10:44
  • I know. My huge problem is the package not showing any errors when it is opened inside a project. Now I discovered another issue when you just have the package opened. Every so often, the package may compile fine with no errors. Then you select a class that you know contains errors and the errors show. Don't ask me why, but everything related to Xcode is a piece of crap and Apple doesn't care. Have I mentioned that I hate Xcode? – Duck Aug 09 '23 at 17:06
  • I personally do not perceive many problems. And if, I can fix them quite quickly. Tip: delete the module cache – it _may_ help. I agree, some subtle build issues may require decades of experience in some not that well known areas, and Xcode's build system is quite complex. I also don't see an alternative (anymore). I would suggest to narrow down the issue as far as you can get, make it reproducible and file your concerns and issues to Apple bug reporter. – CouchDeveloper Aug 11 '23 at 08:07