for the best 1 // Old school approach 2 3 4 5 NSNotificationCenter.defaultCenter().addObserver(self, name:"SomeImportantNote", m selector:Selector("functionName"), object: scopeObj) 6 7 // Elsewhere in code 8 9 NSNotificationCenter.defaultCenter().postNotificationName("SomeimportantNote", object: scopeObj, userInfo: nil) NSNotification
Can we do better? 1 // Slightly less old school approach 2 3 let importantNoteName = "SomeImportantNote" 4 5 NSNotificationCenter.defaultCenter().addObserver(self, name:importantNoteName, m selector:Selector("functionName"), object: scopeObj) 6 7 // Elsewhere in code 8 9 NSNotificationCenter.defaultCenter().postNotificationName(importantNoteName, object: scopeObj, userInfo: nil) NSNotification
case SystemTimeChanged 4 } 1 // Old school 2 NSNotificationCenter.defaultCenter(). addObserver(self, name:"SomeImportantNote", selector:Selector("functionName"), object: scopeObj)
case SystemTimeChanged 4 } 1 // Old school 2 NSNotificationCenter.defaultCenter(). addObserver(self, name:"SomeImportantNote", selector:Selector("functionName"), object: scopeObj) 3 4 // Slightly less old school 5 NSNotificationCenter.defaultCenter(). addObserver(self, name:Notification.SomeImportantNote.rawValue, selector:Selector("functionName"), object: scopeObj)
scopeObj) 3 4 // Slightly less old school 5 NSNotificationCenter.defaultCenter(). addObserver(self, name:Notification.SomeImportantNote.rawValue, selector:Selector("functionName"), object: scopeObj) Is this an improvement?! Notification 1 enum Notification: String { 2 case SomeImportantNote 3 case SystemTimeChanged 4 }