Skip to content

Instantly share code, notes, and snippets.

@VAnsimov
VAnsimov / LifeCycleApp-Example1.swift
Last active November 6, 2020 11:29
Application life cycle
@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
@VAnsimov
VAnsimov / UserDefaultsWrapper.swift
Last active November 3, 2020 14:28
UserDefaultsWrapper
import Foundation
private protocol AnyOptional {
var isNil: Bool { get }
}
extension Optional: AnyOptional {
var isNil: Bool { self == nil }
}