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")!
}
@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)
}
@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,
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 / 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 / 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 / AnimatableTrigger.swift
Created September 3, 2022 01:12
检查可动画数据的状态
//
// AnimatableTrigger.swift
// ScrollViewDemo
//
// Created by Yang Xu on 2022/9/2.
//
import Foundation
import SwiftUI
@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 / adaptiveSheet.swift
Created October 22, 2022 00:53
Adaptive Height Sheet
import SwiftUI
struct ContentView: View {
@State var show = false
var body: some View {
VStack {
Button("Pop Sheet") { show.toggle() }
}
.adaptiveSheet(isPresent: $show) { SheetView() }
}