有没有办法让其他人配置我的 cocoapod 或 swift 包库中使用的常量?
我创建了一个基本 SwiftUI 组件库,其中包括颜色、字体和标准图标的集合。现在,所有组件都引用常量文件来确定主要/次要颜色、标题/段落字体大小和字体以及其他常量等特征。我希望其他开发人员能够导入这个通用的资源和组件层,并根据他们的项目需求在常量文件中“填充空白”。导入库后,开发者还可以利用资源添加更多具体的UI组件,定制自己项目的组件库。
为了获得最大的灵活性,该库既是 cocoapod 又是 swift 包。导入包后,有没有办法创建导入模块引用的某种对象或配置?或者我的想法是错误的/还有其他方法吗?
通用组件库 -->更多项目特定组件库-->在团队项目中使用
常量文件示例:
public class MyConstants {
// MARK: - Colors
public struct Colors {
public static let primary = Color(MSUColors.purple)
public static let highlight = Color(MSUColors.purpleLighter)
public static let secondary = Color(MSUColors.gold)
public static let disabled = Color(MSUColors.grayLight)
public static let text = Color(MSUColors.grayDarker)
public static let border = Color(MSUColors.grayDark)
public static let background = Color(MSUColors.grayUI)
public static let valid = Color(MSUColors.checkmarkGreen)
public static let error = Color(MSUColors.errorRed)
public static let warning = Color(MSUColors.gold)
}
// MARK: - Icons
public struct Icons {
public static let reviewItems = TaskIcon.BillingSettings
public static let dealerCode = TaskIcon.Customer
public static let setAutoPay = TaskIcon.SetAutoPay
public static let caretLeft = IconImage.caretLine.left?.withRenderingMode(.alwaysTemplate)
public static let deviceLabel = TaskIcon.DeviceLabel
public static let printShippingLabel = TaskIcon.PrintShippingLabel
public static let reviewAgreement = TaskIcon.ReviewAgreement
public static let checkmark = IconImage.Checkmarks.self
public static let managerLogin = IconImage.managerLogin
}
// ..etc for other stuff like fonts and sizes
I created a library of basic SwiftUI components that includes a collection of colors, fonts, and standard icons. Right now, all the components reference a constants file for determining characteristics like primary/secondary colors, header/paragraph font sizes and typefaces, and other constants. I want other developers to be able to import this generic layer of resources and components and "fill in the blanks" in the constants file depending on their project needs. After importing the library, the developer can also add more specific UI components using the resources to tailor their own project's component library.
For maximum flexibility, the library is both a cocoapod and a swift package. Is there a way, after importing the package, to create some kind of object or configuration that is referenced by the imported module? Or am I thinking about this wrong/is there another way?
Generic Component Library --> More project specific component library --> used in team's project
Example of constants file:
public class MyConstants {
// MARK: - Colors
public struct Colors {
public static let primary = Color(MSUColors.purple)
public static let highlight = Color(MSUColors.purpleLighter)
public static let secondary = Color(MSUColors.gold)
public static let disabled = Color(MSUColors.grayLight)
public static let text = Color(MSUColors.grayDarker)
public static let border = Color(MSUColors.grayDark)
public static let background = Color(MSUColors.grayUI)
public static let valid = Color(MSUColors.checkmarkGreen)
public static let error = Color(MSUColors.errorRed)
public static let warning = Color(MSUColors.gold)
}
// MARK: - Icons
public struct Icons {
public static let reviewItems = TaskIcon.BillingSettings
public static let dealerCode = TaskIcon.Customer
public static let setAutoPay = TaskIcon.SetAutoPay
public static let caretLeft = IconImage.caretLine.left?.withRenderingMode(.alwaysTemplate)
public static let deviceLabel = TaskIcon.DeviceLabel
public static let printShippingLabel = TaskIcon.PrintShippingLabel
public static let reviewAgreement = TaskIcon.ReviewAgreement
public static let checkmark = IconImage.Checkmarks.self
public static let managerLogin = IconImage.managerLogin
}
// ..etc for other stuff like fonts and sizes
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论