//传统方式 let lightFontTitle =UIFont(name: "Acme-Light", size: 22)
//R.Swift方式 let lightFontTitle =R.font.acmeLight(size: 22)
Resource files - 数据文件
1 2 3 4 5 6 7
//传统方式 let jsonData =Bundle.main.path(forResource: "menuList", ofType: "json") let jsonUrl1 =Bundle.main.url(forResource: "menuList", withExtension: "json")
//R.Swift方式 let jsonData2 =R.file.menuListJson.path() let newUrl =R.file.menuListJson()
Storyboards
1 2 3 4 5 6 7 8 9 10 11 12 13 14
//传统方式 let nibVC1 =UIStoryboard(name: "NibHome", bundle: nil).instantiateInitialViewController() ??UIViewController()
let storyboard =UIStoryboard(name: "Main", bundle: nil) let initialTabBarController = storyboard.instantiateInitialViewController() as?UITabBarController let settingsController = storyboard.instantiateViewController(withIdentifier: "settingsController") as?SettingsControllerSettingsController
//R.Swift方式 let nibVC =R.storyboard.nibHome().instantiateInitialViewController() ??UIViewController()
let storyboard =R.storyboard.main() let initialTabBarController =R.storyboard.main.initialViewController() let settingsController =R.storyboard.main.settingsController()
Nibs
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
//传统方式 let nameOfNib ="CustomView" let customViewNib =UINib(nibName: "CustomView", bundle: nil) let rootViews = customViewNib.instantiate(withOwner: nil, options: nil) let customView = rootViews[0] as?CustomView
let viewControllerWithNib =CustomViewController(nibName: "CustomView", bundle: nil)
//R.Swift方式 let nameOfNib =R.nib.customView.name let customViewNib =R.nib.customView() let rootViews =R.nib.customView.instantiate(withOwner: nil) let customView =R.nib.customView.firstView(owner: nil)
let viewControllerWithNib =CustomViewController(nib: R.nib.customView)