Skip to content

Instantly share code, notes, and snippets.

View fatbobman's full-sized avatar

东坡肘子 fatbobman

View GitHub Profile
@NoahKamara
NoahKamara / CompoundPredicate.swift
Last active May 8, 2024 03:50
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 May 7, 2024 09:07
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 January 29, 2024 16:25
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 March 20, 2024 15:06
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 {
@Sherlouk
Sherlouk / AccessibilityPreview.swift
Created June 8, 2022 20:05
SwiftUI view for adding accessibility previews. Proof of concept.
import SwiftUI
import UIKit
// from https://github.com/cashapp/AccessibilitySnapshot
import AccessibilitySnapshotCore
struct AccessibilityPreview<Content: View>: View {
let content: Content
var body: some View {
@onmyway133
onmyway133 / LayoutInSwiftUI.swift
Created June 8, 2022 09:34
LayoutInSwiftUI.swift
import SwiftUI
import Combine
struct ContentView: View {
var body: some View {
VStack {
Section {
list
.frame(height: 150)
} header: {