2016-05-13 32 views
0

NSNotification関数を呼び出すとエラーが表示されます。これをどうすれば解決できますか?NSNotification関数を呼び出すことができません

にスローされるエラーです。

は、引数の型「NSNotification」

予想される「(NSNotification).TYPE」(別名「NSNotification、タイプ」)型の値を変換できません。

影響を受けるコードブロック:

@IBAction func loginBtn(sender: AnyObject) { 

    let loginobj = Login(userName : self.usernameField.text!, passWord : self.pwdField.text!) 
    loginobj.getRequest() 
    handlingAuthentication(NSNotification) 

} 

これは

呼び出される関数です。 NSNotificationが初期化される
func handlingAuthentication(notification: NSNotification) { 

    let errorDectected = notification.object as! Bool 

    if(errorDectected){ 
     //initialize Alert Controller 
     let alertController = UIAlertController(title: "Authentication error", message: AuthHelpers.sharedInstance.errorMessage, preferredStyle: .Alert) 

     //Initialize Actions 
     let okAction = UIAlertAction(title: "Ok", style: .Default){ 
       (action) -> Void in 
       self.dismissViewControllerAnimated(true, completion: nil) 
      } 

     //Add Actions 
     alertController.addAction(okAction) 

     //Present Alert Controller 
     self.presentViewController(alertController, animated: true, completion: nil) 

    } 
    else 
    { 
     print("error not found") 
     NSUserDefaults.standardUserDefaults().setBool(true, forKey: "isUserLoggedIn") 

     NSUserDefaults.standardUserDefaults().synchronize() 

     self.dismissViewControllerAnimated(true, completion:nil) 

    } 

} 

コード:

var error = "true" 
NSNotificationCenter.defaultCenter().postNotificationName("errorFound", object:error) 

私はそれが正しいかどうか分からないが、私はエラーの値を変更したいとき、私はちょうどこのerror = false

スクリーンショットを行うだろうエラーがスローされました: Error thrown

+0

に渡されましたあなたの質問を正確に私に精緻化できますか? –

+0

それは問題なく解決しました。お手伝いをしてくれてありがとう:) – noobdev

答えて

0

私はちょうど追加する必要があった

に対処するための通知だけでなく、

func handlingAuthentication(notification: NSNotification) { 

    let dict = notification.object as! NSDictionary 
} 

を受信する通知と私のLoginViewControllerコードで

NSNotificationCenter.defaultCenter().addObserver(self, selector: #selector(LoginViewController.handlingAuthentication(_:)), name:"errorPresent", object: nil) 

を投稿するLogin.swiftの私の機能getRequest()の下部に

NSNotificationCenter.defaultCenter().postNotificationName("errorPresent", object:errorDict) 

データは

関連する問題