I am adding a 5 star rating system to the meal tracker app. I will use a custom control that will hold and display the logic required. Essentially, I create a UIStackView subclass to create an independant, modularized view that can be injected independantly into any view.

So far, I have the ugly red button but I will eventually have clickable stars in its place with event handlers tied to the view controller.

custom control

Key concepts

Adding Initializer Placeholders

override init(frame: CGRect) {
    <#code#>
}

init(Frame:) - initializes and returns a newly allocated view object with the specified frame rectangle

required init(coder: NSCoder) {
	super.init(coder: coder)
}

Archiving and Serialization

Convert objects and values to and from property list, JSON, and other flat binary representations

NSCoding - a protocol that enables an object to be encoded and decoded for archiving and distribution

Adding buttons to the Custom Control

// Create the button
let button = UIButton()
button.backgroundColor = UIColor.red

UIButton() - convenience initializer that calls init(frame:) and passes in a zero-sized rectangle.