Skip to content

Instantly share code, notes, and snippets.

View shakemno's full-sized avatar

Manolis Pahlke shakemno

View GitHub Profile
@nilshoenson
nilshoenson / Shader.metal
Last active June 28, 2024 20:51
A wave animation built with shaders in SwiftUI.
#include <metal_stdlib>
#include <SwiftUI/SwiftUI_Metal.h>
using namespace metal;
// Create a horizontal bar
float bar(vector_float2 uv, float start, float height) {
return step(uv.y, height + start) - step(uv.y, start);
}
// Create waves animation using GLSL
// 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
public protocol ObservablePropertySource: ObservableObject {
static var shared: Self { get }
}
@propertyWrapper
public struct ObservableProperty<S: ObservablePropertySource, T>: DynamicProperty {
@ObservedObject private var source: S
@DevAndArtist
DevAndArtist / CustomStateObject.swift
Last active December 15, 2021 17:36
Custom `StateObject` which should be backwards compatible with iOS 13.
import SwiftUI
import Combine
/// The idea is to use State to create a storage object which will be
/// cached and restored by the framework. Then during the update phase we
/// re-inject the object into a nested ObservableObject and subscribe to the
/// ObjectType’s objectWillChange to forward to the _MessageForwarder’s
/// objectWillChange which is already subscribed by the framework as it’s an
/// inner dynamic property of our custom PW which is also a dynamic property.
@propertyWrapper
@krzysztofzablocki
krzysztofzablocki / process.sh
Created January 18, 2021 11:29
3rd party tooling processing script
#!/bin/zsh
cd "$(dirname "$0")/.."
if [[ -n "$CI" ]] || [[ $1 == "--fail-on-errors" ]] ; then
FAIL_ON_ERRORS=true
echo "Running in --fail-on-errors mode"
ERROR_START=""
COLOR_END=""
INFO_START=""
@DougGregor
DougGregor / preventing-data-races.md
Created December 20, 2020 06:49
Preventing Data Races in the Swift Concurrency Model

Preventing Data Races in the Swift Concurrency Model

One of the goals of the concurrency effort is to prevent data races. This document describes the approach taken to preventing data races overall, by categorizing the sources of data races and describing how they are addressed with other proposals in the Swift Concurrency effort.

Data races

A data race occurs when two threads access the same memory concurrently and at least one of the accesses can change the value. Within the safe subset of Swift (e.g., ignoring the use of UnsafeMutablePointer and related types), the memory in question is always a stored property. There are several different categories of stored properties that need to be considered for data races:

  • Global and static stored properties:
@izakpavel
izakpavel / LightningView.swift
Created December 3, 2020 07:34
Lightnings in SwiftUI
//
// Lightnings fun
//
// BEWARE highly unoptimized!
//
// Created by Pavel Zak on 30/11/2020.
//
import SwiftUI
@izakpavel
izakpavel / RotatorView.swift
Created November 18, 2020 09:08
a SwiftUI recreation of an interesting animation by @beesandbombs
//
// RotatorView.swift
//
// Created by Pavel Zak on 16/11/2020.
// original idea by: https://twitter.com/beesandbombs/status/1326312738033983489?s=20
//
import SwiftUI
func pow(_ x: Int, _ y: Int) -> Int {
@douglashill
douglashill / SidebarTest.swift
Created October 9, 2020 18:18
Trivial Catalyst test app to see if `primaryBackgroundStyle = .sidebar` works to get a translucent blurry sidebar on Big Sur
import UIKit
@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {
}
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
private var _window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
@fxm90
fxm90 / Redux.swift
Last active December 12, 2022 10:52
Playground showing how to use Redux with SwiftUI.
//
// Redux.playground
//
// Created by Felix Mau on 25.06.20.
// Copyright © 2020 Felix Mau. All rights reserved.
//
import PlaygroundSupport
import SwiftUI