提问人:Anton Tropashko 提问时间:10/10/2023 最后编辑:Anton Tropashko 更新时间:10/10/2023 访问量:30
swift:每当框架名称中有一个包含框架名称的公共实体时,指定框架中公共结构的路径 [duplicate]
swift: Specifying path to a public struct in a framework whenever framework name has a public entity with the name of the framework in it [duplicate]
问:
假设框架 Foo 有(可悲的公共)类 Foo 和一个公共结构帐户
func fetchClient(guid: String) -> Foo.Account? {
产生编译器错误
“Account”不是类“Foo.Foo”的成员类型
在 Foo 之外访问(公共)帐户的正确语法是什么? (这里有很多关于别名为框架的类的脏话)
答:
2赞
Sweeper
10/10/2023
#1
目前还没有这样的语法。另请参阅 Swift 论坛上的讨论,该论坛正在讨论这个确切的问题。
作为解决方法,您可以仅从以下位置导入结构:Account
Foo
import struct Foo.Account
现在你不会看到这个类,你可以说.Foo
Foo.Account
如果你还需要 类 ,或者很多其他的东西,你可以使用上面的技术,把一个类型别名放在一个单独的文件中。Foo
Foo
Foo.Account
// this is the entirety of the file:
import struct Foo.Account
typealias FooAccount = Account
此外,如果您使用的是 SPM,还有一个模块别名功能,允许您重命名为其他名称。请参阅 Swift Evolution 提案。Foo
评论
import Foo
Account
Account