Last active
March 24, 2022 16:26
-
-
Save eliyap/bf2e23953cabb8a887ec50462d4977cb to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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