Skip to content

Instantly share code, notes, and snippets.

@niw
niw / use_var_in_struct.md
Last active December 1, 2025 02:11
Use `var` in `struct` in Swift

Use var in struct in Swift

TL;DR: Use var for properties in struct as long as it serves as a nominal tuple. In most cases, there is no obvious benefit to using let for struct properties.

Simple Example

Let's start with a simple example:

struct MyStruct {
@realvjy
realvjy / ChoasLinesShader.metal
Last active December 8, 2025 22:02
Choas Lines - Metal Shader
// Lines
float hash( float n ) {
return fract(sin(n)*753.5453123);
}
// Slight modification of iq's noise function.
float noise(vector_float2 x )
{
vector_float2 p = floor(x);
vector_float2 f = fract(x);
@dbolella
dbolella / LinkPreviewWin.swift
Created October 29, 2019 18:57
Working LinkPreview in SwiftUI
struct ContentView: View {
@State var togglePreview = false
var body: some View {
VStack {
URLPreview(previewURL: URL(string: "https://medium.com")!, togglePreview: $togglePreview)
.aspectRatio(contentMode: .fit)
.padding()
}
//------------------------------------------------------------------------
// The SwiftUI Lab: Advanced SwiftUI Animations
// https://swiftui-lab.com/swiftui-animations-part1 (Animating Paths)
// https://swiftui-lab.com/swiftui-animations-part2 (GeometryEffect)
// https://swiftui-lab.com/swiftui-animations-part3 (AnimatableModifier)
//------------------------------------------------------------------------
import SwiftUI
struct ContentView: View {
@pakLebah
pakLebah / launch.json
Last active March 11, 2025 19:44
My VS Code tasks for Apple's Swift programs on Mac.
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"type": "lldb",
"name": "LLDB",
"cwd" : "${workspaceFolder}",