This file contains 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 Foundation | |
private protocol AnyOptional { | |
var isNil: Bool { get } | |
} | |
extension Optional: AnyOptional { | |
var isNil: Bool { self == nil } | |
} |
This file contains 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
@main | |
struct YourApp: App { | |
var body: some Scene { | |
let publisherBackground = NotificationCenter.default.publisher(for: UIApplication.willResignActiveNotification) | |
let publisherForeground = NotificationCenter.default.publisher(for: UIApplication.willEnterForegroundNotification) | |
return WindowGroup { | |
RootView() | |
.onReceive(publisherBackground) { _ in |
This file contains 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 Foundation | |
import ARKit | |
extension ARPlaneAnchor { | |
@discardableResult | |
func addPlaneNode(on node: SCNNode, geometry: SCNGeometry, contents: Any) -> SCNNode { | |
guard let material = geometry.materials.first else { fatalError() } | |
if let program = contents as? SCNProgram { |
This file contains 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 | |
import SwiftUI | |
// SwiftUI | |
struct SomeView: View { | |
var body: some View { | |
Text("Hello World!") | |
} | |
} |
This file contains 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
// 1 | |
final class MVIContainer<Intent, Model>: ObservableObject { | |
// 2 | |
let intent: Intent | |
let model: Model | |
private var cancellable: Set<AnyCancellable> = [] | |
init(intent: Intent, model: Model, modelChangePublisher: ObjectWillChangePublisher) { |
This file contains 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
extension ListView { | |
static func build() -> some View { | |
let model = ListModel() | |
let intent = ListIntent(model: model) | |
let container = MVIContainer( | |
intent: intent, | |
model: model as ListModelStatePotocol, | |
modelChangePublisher: model.objectWillChange) |
This file contains 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
struct ListView: View { | |
// 1 | |
@StateObject private var container: MVIContainer<ListIntent, ListModelStatePotocol> | |
var body: some View { | |
// 2 | |
Text(container.model.text) | |
.padding() | |
.onAppear(perform: { |
This file contains 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
final class ListIntent { | |
// 1 | |
private weak var model: ListModelActionsProtocol? | |
init(model: ListModelActionsProtocol) { | |
self.model = model | |
} | |
func viewOnAppear() { |
This file contains 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
// 1 | |
protocol ListModelStatePotocol { | |
var text: String { get } | |
} | |
// 2 | |
protocol ListModelActionsProtocol: AnyObject { | |
func parse(number: Int) | |
} |
This file contains 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
// 1 | |
final class ListModel: ObservableObject, ListModelStatePotocol { | |
@Published var text: String = "" | |
} | |
// 2 | |
extension ListModel: ListModelActionsProtocol { | |
func parse(number: Int) { | |
text = "Random number: " + String(number) |
OlderNewer