【发布时间】:2022-12-18 22:24:41
【问题描述】:
我在我的工作空间中创建了一个 swift 包。
我遵循本指南只是为了测试一下:
https://sarunw.com/posts/how-to-modularize-existing-ios-projects-using-swift-package/
一切顺利。
我添加到包中的其中一件事是:
public extension Color {
static let customRed:Color = Color(uiColor: UIColor(named: "customRed", in: .module, compatibleWith: nil)!)
}
在将资产添加到实际包后,我从主应用程序的 Assets.xcassets 中删除了 customRed。
现在一切正常,包使用包 Assets.xcassets 中定义的 customRed。
我有很多文件在应用程序中使用 Color.customRed,我想我必须转到每个文件并在顶部为包添加导入语句。所以:
import MyColorPackage
问题:我不明白为什么不这样做应用程序就可以正常工作。文件可以使用 Color.customRed 调用,而无需在使用它的文件顶部添加 import MyColorPackage。如果文件中没有 import MyColorPackage,文件如何使用 customRed?应用程序运行良好,无需在使用 customRed 的文件中导入模块。为什么?
【问题讨论】:
标签: ios swift swift-package-manager