Avatar ·

Comment utiliser correctement NSNotificationCenter addObserver en Swift ?

Bonjour à tous ! Je suis débutant en Swift et j'essaie de comprendre le mécanisme des notifications. J'ai besoin que lorsque les paramètres de l'application changent (par exemple, le changement de langue), tous les écrans actifs en soient informés. J'ai entendu dire qu'on utilise `NSNotificationCenter` pour cela, mais j'ai des problèmes avec son utilisation.\n\nVoici mon code :\n\n```swift\n// Envoi de la notification\nNSNotificationCenter.defaultCenter().postNotificationName("LanguageChanged", object: nil)\n\n// Abonnement à la notification (dans viewDidLoad)\nNSNotificationCenter.defaultCenter().addObserver(self, selector: "languageChanged:", name: "LanguageChanged", object: nil)\n\n// Gestionnaire\nfunc languageChanged(notification: NSNotification) {\n print("Language changed!")\n}\n```\n\nMais Xcode affiche un avertissement : `'addObserver:selector:name:object