Skip to content

Instantly share code, notes, and snippets.

View fatbobman's full-sized avatar

东坡肘子 fatbobman

View GitHub Profile
@Koshimizu-Takehito
Koshimizu-Takehito / MazeGenerator.swift
Last active April 12, 2025 05:23
迷路生成ロジック
import Combine
import Foundation
// MARK: - MazeGenerator (Model)
/// An actor that generates a maze using a depth-first search (DFS) based approach.
/// 深さ優先探索 (DFS) ベースのアルゴリズムを用いて迷路を生成する。
///
/// This actor provides an async stream of snapshots (`MazeGenerator.Snapshot`) so that observers
/// can track the maze's state and generation progress in real time.
import SwiftUI
// Remember to download FontSettings.swift
struct WWDC24AnimatedTextView: View {
var text = "Hello, World!"
var animation: Animation = .easeInOut
var targetFontSize: CGFloat = 40
var minimumFontSize: CGFloat = 30
var targetFontWeight: Font.Weight = .semibold
@NoahKamara
NoahKamara / CompoundPredicate.swift
Last active October 29, 2024 21:19
Combining New Swift Predicates
import Foundation
@available(macOS 14, iOS 17, tvOS 17, watchOS 10, *)
/// Allows you to use an existing Predicate as a ``StandardPredicateExpression``
struct VariableWrappingExpression<T>: StandardPredicateExpression {
let predicate: Predicate<T>
let variable: PredicateExpressions.Variable<T>
func evaluate(_ bindings: PredicateBindings) throws -> Bool {
// resolve the variable
@unixzii
unixzii / WeatherView.swift
Created November 7, 2023 13:21
A demo of implementing iOS Weather card in SwiftUI.
import SwiftUI
struct HeaderView: View {
var body: some View {
HStack {
Image(systemName: "info.circle.fill")
.resizable()
.frame(width: 12, height: 12)
Text("Section Header")
.font(.system(size: 13))
@megabitsenmzq
megabitsenmzq / UIAlertControllerWrapper.swift
Last active August 25, 2023 10:04
Show UIKit alert in SwiftUI.
// SwiftUI alert has so many problems. Use UIKit instead.
import UIKit
struct UIAlertControllerWrapper {
static func present(alert: UIAlertController) {
if let scene = UIApplication.shared.connectedScenes.first as? UIWindowScene, let root = scene.windows.first?.rootViewController {
var nextViewController = root
while nextViewController.presentedViewController != nil {
nextViewController = nextViewController.presentedViewController!
@SmartJSONEditor
SmartJSONEditor / gist:33d796e81554205fd491b6449376c426
Last active March 31, 2024 05:38
Observation withObservationTracking as Combine publisher
import Combine
import Foundation
import Observation
// A: Using specific class
/// Class that wraps withObservationTracking function into a Combine compatible continuos stream publisher
public class ObservationTracker<O: Observable & AnyObject, T> {
/// Subscribe to a publisher.
public var valuePublisher: AnyPublisher<T, Never> {
@beader
beader / 0-InfinitePageView for SwiftUI.md
Last active March 26, 2025 11:33
Create a InfinitePageView for SwiftUI using UIViewControllerRepresentable by the help of ChatGPT

InfinitePageView for SwiftUI

Create a Bi-directional Infinite PageView for SwiftUI using UIViewControllerRepresentable & UIPageViewController by the help of ChatGPT.

Checkout the video demo in the comment.

The code is generated by ChatGPT through multiple rounds of conversations. Checkout the conversations between ChatGPT and me if you are interested in.

@beader
beader / InfiniteScrollChart.swift
Last active August 28, 2024 18:16
Infinite Scrollable Bar Chart using Swift Charts
//
// InfiniteScrollChart.swift
// ChartsGallery
//
// Created by beader on 2022/11/3.
//
import SwiftUI
import Charts
@beader
beader / InfiniteTabView.swift
Last active April 25, 2025 16:33
Infinite Scrollable TabView using SwiftUI
//
// ContentView.swift
// InfinityTabView
//
// Created by beader on 2022/10/9.
//
import SwiftUI
struct ContentView: View {
@ryanlintott
ryanlintott / LayoutThatFits.swift
Last active December 8, 2023 15:14
An alternative to ViewThatFits. Updated version can be found here: https://github.com/ryanlintott/LayoutThatFits
//
// LayoutThatFits.swift
// WWDC22Experiments
//
// Created by Ryan Lintott on 2022-06-08.
//
import SwiftUI
struct LayoutThatFits: Layout {