swift - private func: Missing argument for parameter #1 in call -


well, here's 'missing argument parameter #1 in call' issue. (seems apple better job naming errors :-p )

in class, i'm calling private function libraryvisibility(), , on line missing argument parameter #1 in call error on compilation. don't understand why.

anyhow, here's code:

import cocoa  @nsapplicationmain class appdelegate: nsobject, nsapplicationdelegate {      var librarystate: bool = libraryvisibility()      func applicationdidfinishlaunching(anotification: nsnotification) {         …     }      private func libraryvisibility() -> bool {         …         // dostuff , return boolean         return true     } } 

you can't call instance functions in default initialiser of property

you can either make libraryvisibility() function class function:

@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     } } 

or make librarystate property lazy property:

@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     } } 

the property initialised first time use it.

mike buss has nice usage guide on how use lazy variables.


Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

How to get the ip address of VM and use it to configure SSH connection dynamically in Ansible -

javascript - Get parameter of GET request -