Skip to content

Instantly share code, notes, and snippets.

//
// SFSymbolImage.swift
// SFSymbolVariableValueAnimationWrong
//
// Created by Matthew Young on 12/22/22.
//
import SwiftUI
struct AnimatableVariableValueModifier: Animatable, ViewModifier {
// Author: SwiftUI-Lab (www.swiftui-lab.com)
// Description: This code is part of the "Advanced SwiftUI Animations - Part 5"
// Article: https://swiftui-lab.com/swiftui-animations-part5/
import SwiftUI
struct ContentView: View {
var body: some View {
DigitalRain()
}
import SwiftUI
import WebKit
import Combine
class WebViewData: ObservableObject {
@Published var loading: Bool = false
@Published var scrollPercent: Float = 0
@Published var url: URL? = nil
@Published var urlBar: String = "https://nasa.gov"
@mecid
mecid / Calendar.swift
Last active October 21, 2024 00:38
SwiftUI Calendar view using LazyVGrid
import SwiftUI
extension Calendar {
func generateDates(
inside interval: DateInterval,
matching components: DateComponents
) -> [Date] {
var dates: [Date] = []
dates.append(interval.start)
@SpectralDragon
SpectralDragon / PreviewContextMenu.swift
Created April 8, 2020 19:22
Simple way to implement preview context menu for SwiftUI
//
// ContentView.swift
// PreviewSwiftUI
//
// Created by v.prusakov on 4/8/20.
// Copyright © 2020 v.prusakov. All rights reserved.
//
import SwiftUI
@mdiep
mdiep / diff-values.swift
Last active February 13, 2024 21:01
Diff values with Codable, CaseIterable, and KeyPaths
import Foundation
// Diff objects for better test assertions.
//
// Implemented in a way that:
// 1. The compiler generates as much code as possible
// 2. You'll get a compiler error if you forget a property
//
// Nested support and collections left as an exercise for the reader.
@RoLYroLLs
RoLYroLLs / DeviceConstant.swift
Created December 31, 2019 19:03
A list of all Apple device names easily accessible through enums. particularly useful for PreviewProvider in Swift
//
// DeviceConstants.swift
// SampleApp
//
// Created by RoLY roLLs on 12/31/19.
// Copyright © 2019 RoLYroLLs Enterprises, LLC. All rights reserved.
//
/// Taken from https://developer.apple.com/documentation/swiftui/securefield/3289399-previewdevice
@mecid
mecid / PagerView.swift
Last active August 15, 2024 06:38
PagerView in SwiftUI
//
// PagerView.swift
//
// Created by Majid Jabrayilov on 12/5/19.
// Copyright © 2019 Majid Jabrayilov. All rights reserved.
//
import SwiftUI
struct PagerView<Content: View>: View {
let pageCount: Int
@verebes1
verebes1 / ColorSupport.swift
Last active August 18, 2021 19:09
Using UIColors from iOS13 with backward compatibility to previous iOS versions.
import UIKit
public enum ColorSupport {
public static var label: UIColor {
if #available(iOS 13, *) {
return .label
}
return UIColor(red: 0.0, green: 0.0, blue: 0.0, alpha: 1.0)
}
@eospi
eospi / RealityKitGestures.swift
Created August 13, 2019 16:08
Gestures in RealityKit
import RealityKit
import UIKit
class ViewController: UIViewController {
let arView: ARView
func addGestures() {
// Use any entity. Here we're using a cube with size 0.5m
let entity = ModelEntity(mesh: MeshResource.generateBox(size: 0.5))
entity.generateCollisionShapes(recursive: true)