嗯,这是另一个'呼叫'问题中参数#1的缺失参数。 (似乎Apple可以更好地命名其错误:-p)
在我的班级中,我正在调用一个私有函数$_SESSION[*]
,在那一行上,我在编译时遇到libraryVisibility()
错误。不明白为什么。
无论如何,这是代码:
Missing argument for parameter #1 in call
答案 0 :(得分:1)
您可以将libraryVisibility()
功能设为class
功能:
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
var libraryState : Bool = AppDelegate.libraryVisibility()
private class func libraryVisibility() -> Bool {
let homeUrl = NSURL(string: NSHomeDirectory())
let libraryUrl = NSURL(string: "Library", relativeToURL: homeUrl)
return libraryUrl!.hidden
}
}
或者您可以将libraryState
属性设为lazy
属性:
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
lazy var libraryState : Bool = self.libraryVisibility()
private func libraryVisibility() -> Bool {
let homeUrl = NSURL(string: NSHomeDirectory())
let libraryUrl = NSURL(string: "Library", relativeToURL: homeUrl)
return libraryUrl!.hidden
}
}
该属性将在您第一次使用时初始化。
Mike Buss has a nice usage guide on how to use lazy
variables.
答案 1 :(得分:0)
好的,我已经解决了,但并不完全确定为什么会这样:
将libraryState
变量设为默认值并将其设置在applicationDidFinishLaunching
内似乎可以解决问题:
@NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
var libraryState: Bool = false
func applicationDidFinishLaunching(aNotification: NSNotification) {
libraryState = libraryVisibility()
}
}