R.swift 使用详解
2022-05-13 本文已影响0人
nick5683
R.swift 使用详解
R.Swift 能快速访问本地图片、颜色、字体等资源的一个库
1、工程中倒入R.swift 以pod为例
pod 'R.swift'

2、配置执行脚本
"$PODS_ROOT/R.swift/rswift" generate "$SRCROOT/R.generated.swift"
$SRCROOT/R.generated.swift


注意添加的脚本不能放在最后,要放在 Compile Sources之前, 否则会有如下错误

3、编译项目 将生成的文件R.genarated.swift
引用到项目根目录中,切记⚠️:不要勾选Copy items if needed

4、使用如下 在新增了图片或者颜色等资源需要 clean Command + K
项目 再编译 Command+R
. 就能访问了

