resource_bundles & resources封装独立库时资源引用方式探讨

本文探讨了在CocoaPods中创建独立库时,使用resource_bundles和resources两种资源引用方式的优缺点。resource_bundles能避免同名资源冲突并优化资源管理,但可能需要硬编码获取;而resources可能导致资源冲突,但在Swift中可能更易使用。建议使用resource_bundles以提高兼容性。
摘要由CSDN通过智能技术生成

1、资源文件引用的方式

CocoaPods 两种资源文件引用的方式——resource_bundles & resources

1-1、resource_bundles

resource_bundles 允许定义当前 Pod 库的资源包的名称和文件。用 hash 的形式来声明,key 是 bundle 的名称,value 是需要包括的文件的通配 patterns。

We strongly recommend library developers to adopt resource bundles as there can be name collisions using the resources attribute.

CocoaPods 官方强烈推荐使用 resource_bundles,因为用 key-value 可以避免相同名称资源的名称冲突。

同时建议 bundle 的名称至少应该包括 Pod 库的名称,可以尽量减少同名冲突

Examples:

ss.resource_bundles = {          'KZWUI' => 'KZWUtils/Assets/*.xcassets'      }

1-2、 resources

使用 resources 来指定资源,被指定的资源只会简单的被 copy 到目标工程中(主工程)。

We strongly recommend library developers to adopt resource bundles as there can be name collisions using the resources attribute. Moreover, resources specified with this attribute are copied
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值