有没有办法让其他人配置我的 cocoapod 或 swift 包库中使用的常量?

发布于 2025-01-20 04:33:29 字数 1832 浏览 3 评论 0原文

我创建了一个基本 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文