0
NSNotification関数を呼び出すとエラーが表示されます。これをどうすれば解決できますか?NSNotification関数を呼び出すことができません
にスローされるエラーです。
予想される「(NSNotification).TYPE」(別名「NSNotification、タイプ」)型の値を変換できません。は、引数の型「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
に渡されましたあなたの質問を正確に私に精緻化できますか? –
それは問題なく解決しました。お手伝いをしてくれてありがとう:) – noobdev