ios - Function produces expected type '(() -> ())?'; did you mean to call it with '()'? -


function produces expected type '(() -> ())?'; did mean call '()'?

i getting above error. auto fix xcode not help.

the error on self.performoncommunicationqueue():

func getauthparams(authclosure:((error:nserror?) -> ())?) {     logdebug("starting sync session max device")      if let statuserror = self.assertready() {         logerror("start sync session failed error: \(statuserror)")          if (authclosure != nil) {             authclosure!(error: statuserror)         }     } else {         self.performoncommunicationqueue() {             let error:nserror?              // set random starting byte             let oabstime:[uint64] = [mach_absolute_time()]             let payload:nsdata = nsdata(bytes: oabstime, length: 8)             let abstime:uint8 = unsafepointer<uint8>(payload.bytes).memory             self.randomcryptobyte = (0x01 | ( abstime & 0xfe))     } }  func sendauthchallenge(authchal:string, completion:((error:nserror?) -> ())?) { }  func performoncommunicationqueue(closure:(()->())?){     if (closure != nil)     {         self.communicationqueue?.addoperationwithblock(closure!)     } } 

i think want:

self.performoncommunicationqueue({ () -> () in     let error:nserror?     // set random starting byte     let oabstime:[uint64] = [mach_absolute_time()]     let payload:nsdata = nsdata(bytes: oabstime, length: 8)     let abstime:uint8 = unsafepointer<uint8>(payload.bytes).memory     self.randomcryptobyte = (0x01 | ( abstime & 0xfe)) }) 

this creates void void closure performoncommunicationqueue requires.

also, check braces match once you've made change, think might 1 short, why autocomplete wasn't help.


Comments