Skip to content

Instantly share code, notes, and snippets.

@drewolbrich
drewolbrich / WireframeTessellatedIcosahedronEntity.swift
Last active September 18, 2024 23:05
A spherical wireframe tessellated icosahedron RealityKit entity
//
// WireframeTessellatedIcosahedronEntity.swift
//
// Created by Drew Olbrich on 9/18/24.
// Copyright © 2024 Lunar Skydiving LLC. All rights reserved.
//
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@drewolbrich
drewolbrich / OnScrollPhaseChange_visionOS2.swift
Created August 19, 2024 16:54
A wrapper around onScrollPhaseChange that applies it only on visionOS 2 and is a no-op on visionOS 1
//
// OnScrollPhaseChange_visionOS2.swift
//
// Created by Drew Olbrich on 7/23/24.
// Copyright © 2024 Lunar Skydiving LLC. All rights reserved.
//
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@drewolbrich
drewolbrich / Entity+FindEntity.swift
Last active August 11, 2024 03:38
A RealityKit Entity extension that finds the first entity in a hierarchy that satisfies a predicate
//
// Entity+FindEntity.swift
//
// Created by Drew Olbrich on 12/30/23.
// Copyright © 2023 Lunar Skydiving LLC. All rights reserved.
//
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@drewolbrich
drewolbrich / LazyAsync.swift
Last active August 11, 2024 03:32
An async-safe lazy variable wrapper, possibly suitable for using with global variables in Swift 6
/// An async-safe lazy variable wrapper, possibly suitable for using with global
/// variables in Swift 6.
///
/// From https://developer.apple.com/documentation/realitykit/rendering-a-windowed-game-in-stereo
actor LazyAsync<T: Sendable> {
private var value: T?
private let closure: () async -> T
@drewolbrich
drewolbrich / Task+SleepForSeconds.swift
Last active August 11, 2024 03:34
A replacement for iOS 17 Task/sleep(for: .seconds(_)) that works on iOS 16 and earlier
//
// Task+SleepForSeconds.swift
//
// Created by Drew Olbrich on 7/12/24.
// Copyright © 2024 Lunar Skydiving LLC. All rights reserved.
//
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@drewolbrich
drewolbrich / PushWindow_visionOS2.swift
Last active August 12, 2024 02:45
A workaround for pushWindow not being available on visionOS 1.
//
// PushWindow_visionOS2.swift
//
// Created by Drew Olbrich on 7/1/24.
// Copyright © 2024 Lunar Skydiving LLC. All rights reserved.
//
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@drewolbrich
drewolbrich / InputNotWorkingIndicator.swift
Last active August 11, 2024 03:33
A recreation of the Mac Virtual Display "Input temporarily not working" indicator
//
// InputNotWorkingIndicator.swift
//
// Created by Drew Olbrich on 6/26/24.
// Copyright © 2024 Lunar Skydiving LLC. All rights reserved.
//
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@drewolbrich
drewolbrich / VolumeBaseplateVisibility_visionOS2.swift
Last active August 11, 2024 03:34
A wrapper around volumeBaseplateVisibility that applies it only on visionOS 2 and later, and is a no-op on visionOS 1
//
// VolumeBaseplateVisibility_visionOS2.swift
//
// Created by Drew Olbrich on 6/25/24.
// Copyright © 2024 Lunar Skydiving LLC. All rights reserved.
//
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@drewolbrich
drewolbrich / VolumeWorldAlignment_visionOS2.swift
Last active August 11, 2024 03:35
A wrapper around visionOS 2 volumeWorldAlignment that is a no-op in visionOS 1
//
// VolumeWorldAlignment_visionOS2.swift
//
// Created by Drew Olbrich on 6/15/24.
// Copyright © 2024 Lunar Skydiving LLC. All rights reserved.
//
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
@drewolbrich
drewolbrich / DefaultWindowPlacement_visionOS2.swift
Last active August 11, 2024 03:35
A wrapper around SwiftUI defaultWindowPlacement that is a no-op on visionOS 1
//
// DefaultWindowPlacement_visionOS2.swift
//
// Created by Drew Olbrich on 6/11/24.
// Copyright © 2024 Lunar Skydiving LLC. All rights reserved.
//
// MIT License
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal