如何调试和构建一个 Swift 包,并且为什么包内的公共类仍然无法被看到?

huangapple go评论98阅读模式
英文:

How to debug and build a swift package from a project and why public classes inside the package are still not seen?

问题

我创建了一个编译正常的Swift包。

我在项目中导入了这个Swift包。

项目中看不到包中的任何类,所以我将它们设为了public。

我在需要的地方添加了public init() {}

方法仍然看不到。

所以我在项目中修改了包中的代码,但Xcode不会编译包或检查任何错误。因此,我在包中看不到任何错误。

因此,我必须关闭项目,打开包以查看错误,进行修改和测试,然后关闭包,打开项目。

这是必要的,因为如果打开了使用该包的项目,Xcode将不允许查看该包。

真是让人恼火。

有没有一种方法可以在项目中编译和调试包?而不需要关闭一个并打开另一个?

从Xcode的顶部栏更改包不起作用。

为什么包中的公共类和方法在项目中仍然看不到?我需要在清单中添加什么吗?

我的清单是由Xcode默认创建的。该包没有依赖项,只是我多年来创建的一组类和类扩展。

总结一下:我有一个“包”和一个“项目”,项目依赖于该包(作为本地Swift包)。当我打开项目时,包中的错误没有被报告,并且类不是public,即使它们已经被声明为public(我通过Sweeper的评论添加了这个注释来澄清事情)

英文:

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).

答案1

得分: 1

使用你描述的方法添加一个包似乎没有执行最后一步,即将其添加到目标中。如果你在目标的常规设置中的“Frameworks、Libraries and Embedded Content”中这样做,它会起作用。尽管我承认,我不得不多次启动Xcode才能让它停止抱怨。

英文:

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.

答案2

得分: 0

我喜欢Xcode。解决这个问题的答案是从项目中移除该包并重新添加。

英文:

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

huangapple
  • 本文由 发表于 2023年8月9日 17:13:41
  • 转载请务必保留本文链接:https://go.coder-hub.com/76866235.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定