使用R swift來管理資源

2021-09-11 12:24:35 字數 4221 閱讀 3374

常見的操作: 1 => let icon = uiimage(named: "settings-icon") 2 => let font = uifont(name: "san francisco", size: 42) 3 => performseguewithidentifier("opensettings")

替代方案: 1 => let icon = r.image.settingsicon 2 => let font = r.font.sanfrancisco(size:42) 3 => performseguewithidentifier(r.segue.opensettings)

使用原生swift

複製**r.swift

複製**使用原生swift

let storyboard = uistoryboard(name: "main", bundle: nil)

let initialtabbarcontroller = storyboard.instantiateinitialviewcontroller() as? uitabbarcontroller

let settingscontroller = self.instantiateviewcontrollerwithidentifier("settingscontroller") as? settingscontroller

複製**

r.swift

let storyboard = r.storyboard.main.instance

let initialtabbarcontroller = r.storyboard.main.initialviewcontroller

let settingscontroller = r.storyboard.main.settingscontroller

複製**

//通過這個**來校驗執行時storyboard的是否都能被載入

// 只在debug模式下有效,會通過斷言來提示

r.storyboard.main.validateimages()

//在執行時校驗所有的viewcontroller能夠被正常載入

mode.r.storyboard.main.validateviewcontrollers()

複製**

使用原生swift

performsegue(withidentifier: "opensettings", sender: self)

override func prepare(for segue: uistoryboardsegue, sender: any?)

}複製**

r.swift

performsegue(withidentifier: r.segue.overviewcontroller.opensettings, sender: self)

override func prepare(for segue: uistoryboardsegue, sender: any?)

複製**

使用原生swift

let nameofnib = "customview"

let customviewnib = uinib(nibname: "customview", bundle: nil)

let rootviews = customviewnib.instantiatewithowner(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.instantiatewithowner(nil, options: nil)

let customview = r.nib.customview.firstview(nil, options: nil)

let viewcontrollerwithnib = customviewcontroller(nib: r.nib.customview)

複製**

使用原生swift

let textcellnib = uinib(nibname: "textcell", bundle: nil)

tableview.registernib(textcellnib, forcellreuseidentifier: "textcellidentifier")

複製**

r.swift

tableview.registernib(r.nib.textcell)

//cellforrowatindexpath中獲取cell

let textcell = tableview.dequeuereusablecellwithidentifier(r.nib.textcell.reuseidentifier, forindexpath: indexpath)

複製**

使用原生swift

let lightfonttitle = uifont(name: "acme-light", size: 22)

複製**

r.swift

let lightfonttitle = r.font.acmelight(size: 22)

複製**

使用原生swift

let jsonurl = nsbundle.mainbundle().urlforresource("seed-data", withextension: "son")

複製**

r.swift

let jsonurl = r.file.seeddatajson

複製**

使用原生swift

let welcomemessage = nslocalizedstring("welcome.message", comment: "")

let settingstitle = nslocalizedstring("title", tablename: "settings", comment: "")

let welcomename = string(format: nslocalizedstring("welcome.withname", comment: ""), locale: nslocale.current, "alice")

let progress = string(format: nslocalizedstring("copy.progress", comment: ""), locale: nslocale.current, 4, 23)

複製**

r.swift

let welcomemessage = r.string.localizable.welcomemessage()

let settingstitle = r.string.settings.title()

let welcomename = r.string.localizable.welcomewithname("alice")

let progress = r.string.localizable.copyprogress(completed: 4, total: 23)

複製**

以物件來管理資源

c 中區域性變數在作用域裡的構造和析構行為,為資源的管理提供了靈活安全的解決之道。下面以多執行緒的鎖來舉例 ifndef lock h define lock hclass lock endif lock h include lock.h lock lock mutex m mutex m lock...

使用winform來遞迴實現資源管理器

這裡主要是對treeview控制項的學習 所使用到的方法 string path e 歌詞 獲得指定資料夾下所有資料夾的名稱,這是帶路徑的,如 e 歌詞 1111111 directory.getdirectories path 獲得指定路徑下的檔案的檔名,不帶路徑與字尾名 如 01 welcome...

用網盤和git來管理資源

現在的網盤很多,比如dropbox 快盤 skydriver 115網盤 雲諾 堅果鋪子等,並且功能很強大,大部分提供的客戶端都有自動版本管理和加密傳輸的功能。這為我們管理我們的資源提供了便利條件,一般的資源直接使用網盤已經做夠了。但是我們有這樣的情況,你在家裡突然有乙個 的想法需要實現,但是你無法...