Skip to content

Instantly share code, notes, and snippets.

@clc80
Last active June 12, 2020 01:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save clc80/10ff8d08df0cf3f9768be1f4ea09ab9a to your computer and use it in GitHub Desktop.
Save clc80/10ff8d08df0cf3f9768be1f4ea09ab9a to your computer and use it in GitHub Desktop.
Objective challenge:
Q1) Pair off, and with a peer, each choose a design pattern and think of an instance you’ve used it code you’ve written or have seen it used in UIKit.
A1) We have used the MVC pattern in our beginning projects. We used this design pattern in our first build week project.
Objective challenge:
Q2)Look through the documentation and find at least one UIKit class that uses the singleton pattern.
A2) App Delegate
Objective challenge:
Q3) Think about a time we’ve used the facade pattern before. Are there places that we could have used it to write better code but didn’t? Discuss with a peer.
A3) Table View
Objective challenge:
Q4) Write code to post a notification when a button is tapped indicating a bell has rung. In another class, sign up to be notified when this notification is posted, and make sure it works.
A4) A “listener” that listens for notifications, called an observer
A “sender” that sends notifications when something happens
The notification center itself, that keeps track of observers and notifications
Here’s how you register an observer:
NotificationCenter.default.addObserver(self, selector: #selector(onDidReceiveData(_:)), name: .didReceiveData, object: nil)
Posting a notification:
NotificationCenter.default.post(name: .didReceiveData, object: nil)
Objective challenge:
Add support for state restoration to another app you’ve built.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment