Skip to content

Instantly share code, notes, and snippets.

View fatbobman's full-sized avatar

东坡肘子 fatbobman

View GitHub Profile
@fatbobman
fatbobman / codeForPersistentHistoryTrackingTopic1.swift
Created August 19, 2021 11:43
code for 在CoreData中使用持久化历史跟踪
public extension UserDefaults {
/// 用于app group的userDefaults,在此处设定的内容可以被app group中的成员使用
static let appGroup = UserDefaults(suiteName: "group.com.fatbobman.healthnote")!
}
import SwiftSyntax
import SwiftSemantics
import Foundation
let source = try! String(contentsOf: URL(fileURLWithPath: "/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS13.2.sdk/System/Library/Frameworks/SwiftUI.framework/Modules/SwiftUI.swiftmodule/arm64e.swiftinterface"))
var collector = DeclarationCollector()
let tree = try SyntaxParser.parse(source: source)
tree.walk(&collector)
@fatbobman
fatbobman / publishedObject.swift
Last active May 11, 2022 10:03
Similar to the @published implementation. Reference type support
@propertyWrapper
public struct PublishedObject<Value: ObservableObject> { // wrappedValue 要求符合 ObservableObject
public var wrappedValue: Value
public init(wrappedValue: Value) {
self.wrappedValue = wrappedValue
}
public static subscript<OuterSelf: ObservableObject>(
_enclosingInstance observed: OuterSelf,
@fatbobman
fatbobman / Transcriptions_Data.swift
Created August 18, 2022 01:18
在 SwiftUI 中,基于 Text 实现关键字查找与检索 —— 演示数据
struct Transcription: Equatable, Identifiable {
let id = UUID()
let startTime: String
var context: String
}
let regexPattern = "Fireflies"
let transcriptionFakeResult: [Transcription] = [
.init(startTime: "06:32", context: "*fiRefLIes As you use fiRefLIes to Fireflies record and transcribe meetings, please ensure that you are followfiRefLIesing all FIREFLIEscountry, state, local, and org level laws around consent."),
@fatbobman
fatbobman / modalMenu.swift
Created August 26, 2022 08:33
通过状态显示遮盖层,让 Menu 具备模态视图的特征( 防止误触 )
struct ModalMenu: View {
@State private var menuIsShowing = false
@State private var selection: Int?
let colors: [Color] = [Color.red, .blue, .green, .orange, .pink, .cyan, .brown]
var body: some View {
VStack {
if let selection {
Text("CurrentID: \(selection)")
} else {
Text("No ID selected")
@fatbobman
fatbobman / FreeSpaceViewController.swift
Created October 8, 2022 00:14 — forked from kylehowells/FreeSpaceViewController.swift
UIViewController subclass to show both the Settings app displayed free space, and the real free space.
//
// FreeSpaceViewController.swift
// Free Space
//
// Created by Kyle Howells on 04/05/2022.
//
import UIKit
class FreeSpaceViewController: UIViewController {
@fatbobman
fatbobman / InfiniteScrollChart.swift
Created November 7, 2022 03:59 — forked from beader/InfiniteScrollChart.swift
Infinite Scrollable Bar Chart using Swift Charts
//
// InfiniteScrollChart.swift
// ChartsGallery
//
// Created by beader on 2022/11/3.
//
import SwiftUI
import Charts
@fatbobman
fatbobman / disableNavigationViewGesture.swift
Created November 7, 2022 07:43
避免在 dismiss Sheet 后快速返回 NavigationView 上层视图导致的应用锁死
/*
当在 NavigationView 非根视图中显示 sheet 时,在 dismiss Sheet 后快速用手势( 从左向右 )返回上层视图会导致整个 UI 锁死,
应用从此无法响应。写了个 ViewModifer ,来避免这种情况
*/
public extension Notification.Name {
static let disableNavigationViewGesture = Notification.Name("disableNavigationViewGesture")
}
public struct NavigationViewGestureMaskModifier: ViewModifier {
@State private var enable = false
@fatbobman
fatbobman / ModelMenu.swift
Last active April 12, 2023 02:22
模态 Menu 用法演示
import Foundation
import SwiftUI
// https://discord.com/channels/967978112509935657/967978112509935663/1012284708685619253 原始问题
struct ModalMenu: View {
@State private var menuIsShowing = false
@State private var selection: Int?
let colors: [Color] = [Color.red, .blue, .green, .orange, .pink, .cyan, .brown]
var body: some View {
@fatbobman
fatbobman / interactiveDismissDisabledExtension.swift
Created September 15, 2021 06:25
SwiftUI interactiveDismissDisabled extension
import SwiftUI
import UIKit
struct SetSheetDelegate: UIViewRepresentable {
let delegate:SheetDelegate
init(isDisable:Bool,attempToDismiss:Binding<UUID>){
self.delegate = SheetDelegate(isDisable, attempToDismiss: attempToDismiss)
}