Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build an Interactive Story App with Swift 2 Refactoring the Model Layer Communicating Via Notifications

Aaron Kaye
Aaron Kaye
10,948 Points

Question about the deinit method

I have a question about the deinit method here. It is just a simple one that removes ourselves as an observer for the keyboard will show broadcast.

deinit {
        // Only needed for iOS less than 9 otherwise iOS does it automatically
        NotificationCenter.default.removeObserver(self, name: .UIKeyboardWillShow, object: nil)
    }

Pasan said that we only need this for iOS 9 and lower. Would best practice be to leave it in 'just in case' the project changes and you now need to support a lower iOS or would best practice be to keep your code clear and if it changes try and remember to go back and change these things. What happens if you were to change your project to iOS 7-8 (for example) and then forget to remove ourselves as the observer?