Skip to content

Instantly share code, notes, and snippets.

Avatar

东坡肘子 fatbobman

View GitHub Profile
@fatbobman
fatbobman / publishedObject.swift
Created Jan 20, 2022
Similar to the @published implementation. Reference type support
View publishedObject.swift
@propertyWrapper
public struct PublishedObject<Value: ObservableObject> {
public static subscript<EnclosingSelf: ObservableObject>(
_enclosingInstance observed: EnclosingSelf,
wrapped wrappedKeyPath: ReferenceWritableKeyPath<EnclosingSelf, Value>,
storage storageKeyPath: ReferenceWritableKeyPath<EnclosingSelf, PublishedObject>
) -> Value where EnclosingSelf.ObjectWillChangePublisher == ObservableObjectPublisher {
get {
observed[keyPath: storageKeyPath].setChanger(observer: observed)
return observed[keyPath: storageKeyPath].wrappedValue
@fatbobman
fatbobman / interactiveDismissDisabledExtension.swift
Created Sep 15, 2021
SwiftUI interactiveDismissDisabled extension
View interactiveDismissDisabledExtension.swift
import SwiftUI
import UIKit
struct SetSheetDelegate: UIViewRepresentable {
let delegate:SheetDelegate
init(isDisable:Bool,attempToDismiss:Binding<UUID>){
self.delegate = SheetDelegate(isDisable, attempToDismiss: attempToDismiss)
}
@fatbobman
fatbobman / codeForPersistentHistoryTrackingTopic1.swift
Created Aug 19, 2021
code for 在CoreData中使用持久化历史跟踪
View codeForPersistentHistoryTrackingTopic1.swift
public extension UserDefaults {
/// 用于app group的userDefaults,在此处设定的内容可以被app group中的成员使用
static let appGroup = UserDefaults(suiteName: "group.com.fatbobman.healthnote")!
}