The documentation for the NSApplicationMain
function說,它NSApplicationMain如何找到主要的筆尖文件?
負載從應用程序的主束主要筆尖文件
它建議NSApplicationMain
通過查看Info.plist
文件在發現「的主要筆尖文件」在網絡上關鍵NSMainNibFile
(由的XCode混淆爲「主筆尖文件基本名稱」),即NSApplicationMain
確實像
let mainBundle: Bundle = Bundle.main
let mainNibFileBaseName: String = mainBundle.infoDictionary!["NSMainNibFile"] as! String
mainBundle.loadNibNamed(mainNibFileBaseName, owner: myApp, topLevelObjects: nil)
但是,如果我刪除NSMainNibFile
密鑰,應用程序仍會找到並加載我的MainMenu.xib
文件!然後,如果我將文件重命名爲Foo.xib
,則應用程序會查找並加載Foo.xib
!
NSApplicationMain
用來查找「主筆尖文件」的真實搜索程序是什麼?
非常簡明明確的答案,謝謝!作爲參考:['load Nib命名(_:owner:options:)'](https://developer.apple.com/reference/foundation/bundle/1618147-loadnibnamed)和['path(for資源:類型:)'](https://developer.apple.com/reference/foundation/bundle/1410989-path) – jameshfisher
我有點困惑,因爲'加載Nib命名(_: owner:options:)'不允許'nil'作爲第一個參數。此行爲是否記錄在案? – jameshfisher
不,但Objective-C不介意。 [loadNibNamed:owner:](https://developer.apple.com/reference/foundation/nsbundle/1402904-loadnibnamed)已棄用。 – Willeke