使用する関数のobject
パラメータは、パラメータではなく通知を送信する送信者です。ドキュメントhereをチェックしてください。
あなたは以下の方法ユーザ情報辞書のパラメータとして送信し、使用する列挙型の値に置く必要があります:あなたのケースでは
func postNotificationName(_ aName: String,
object anObject: AnyObject?,
userInfo aUserInfo: [NSObject : AnyObject]?)
を:
let userInfo = ["RuleError" : RuleError.Create.rawValue]
NSNotificationCenter.defaultCenter().postNotificationName("RuleFailNotification",
object: self,
userInfo:userInfo)
をさらに処理するために通知、最初の登録:
NSNotificationCenter.defaultCenter().addObserver(
self,
selector: "handleRuleFailNotification:",
name: "RuleFailNotification",
object: nil)
次に対処:
func handleRuleFailNotification(notification: NSNotification) {
let userInfo = notification.userInfo
RuleError(rawValue: userInfo!["RuleError"] as! String)
}
これは不幸な必然であるから解除することを忘れないでください。 Notificationsはenumとstructを強制的に第2クラスの状態にします。 Enumは制限されたIntやStringであることが多いので、これはSwiftの主な欠点だと思っていますが、これらは値としては問題ありません。 – BaseZen