Skip to content

Instantly share code, notes, and snippets.

@eliyap
Last active March 24, 2022 16:26
Show Gist options
  • Save eliyap/bf2e23953cabb8a887ec50462d4977cb to your computer and use it in GitHub Desktop.
Save eliyap/bf2e23953cabb8a887ec50462d4977cb to your computer and use it in GitHub Desktop.
import UIKit
/// Represents a view that will send messages, e.g. button presses.
final class SenderView: UIView {
private let myButton: UIButton
@MainActor
init() {
self.myButton = .init()
super.init(frame: .zero)
let action = UIAction { (action) in
/// TODO: Send message to `ReceiverView`...
}
myButton.addAction(action, for: .touchUpInside)
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
/// Represents a view that responds to events.
final class ReceiverView: UIView {
@MainActor
init() {
super.init(frame: .zero)
}
func didReceiveMessage() {
print("Got a message from SenderView!")
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
/// Represents some controller coordinating senders and receivers.
final class MyViewController : UIViewController {
let senderView: SenderView
let receiverView: ReceiverView
@MainActor
init() {
senderView = .init()
receiverView = .init()
super.init(nibName: nil, bundle: nil)
view.addSubview(senderView)
view.addSubview(receiverView)
/// Layout stuff here...
/// TODO: connect sender to receiver...
}
required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment