https://github.com/zhiguangqiao/R.swift
1
2
3
|
leticon=UIImage(named:
"settings-icon"
)
letfont=UIFont(name:
"SanFrancisco"
,size:42)
performSegueWithIdentifier(
"openSettings"
)
|
这种通过传入字符串来获取资源有很大的潜在的风险:
R如何解决上面的问题:
-
强类型
使用一个资源前,先声明是什么类型。如果是一个图片资源就是R.image.xx。这样每次明确知道使用的资源类型。(swift是一门强类型语言,强类型的一个好处就是很多错误可以在编译时就发现)
因为会自动根据资源文件生成结构体,所以可以直接使用,不用自己拼写资源名
支持的资源类型
//使用R.swift之前
letsettingsIcon=UIImage(named:
)
letgradientBackground=UIImage(named:
"gradient.jpg"
)
//使用R.swift
letsettingsIcon=R.image.settingsIcon
letgradientBackground=R.image.gradientJpg
|
letstoryboard=UIStoryboard(name:
"Main"
ottom:auto!important; float:none!important; height:auto!important; left:auto!important; line-height:1.1em!important; outline:0px!important; overflow:visible!important; position:static!important; right:auto!important; top:auto!important; vertical-align:baseline!important; width:auto!important; font-family:Consolas,bundle:nil)
letinitialTabBarController=storyboard.instantiateInitialViewController()as?UITabBarController
letsettingsController=self.instantiateViewControllerWithIdentifier(
"settingsController"
)as?SettingsController
//使用R.swift
letstoryboard=R.storyboard.main.instance
letinitialTabBarController=R.storyboard.main.initialViewController
letsettingsController=R.storyboard.main.settingsController
//只在debug模式下有效,会通过断言来提示
R.storyboard.main.validateImages()
//在运行时校验所有的viewController能够被正常加载
mode.R.storyboard.main.validateViewControllers()
|
)
//使用R.swift
Nibs
相关文章软件简介:蓝湖辅助工具,减少移动端开发中控件属性的复制和粘...
现实生活中,我们听到的声音都是时间连续的,我们称为这种信...
前言最近在B站上看到一个漂亮的仙女姐姐跳舞视频,循环看了亿...
【Android App】实战项目之仿抖音的短视频分享App(附源码和...
前言这一篇博客应该是我花时间最多的一次了,从2022年1月底至...
因为我既对接过session、cookie,也对接过JWT,今年因为工作...
|