Skip to content

Instantly share code, notes, and snippets.

# If you're using SwiftLint, add this to your swiftlint.yml to make Xcode
# generate warnings when you create new Swift files and Xcode inserts the
# filename where the package name should be.
custom_rules:
# This calls out an Xcode 13 bug where the header comments of newly created
# files include the file name where the package name should be.
xcode_13_header_comment_bug:
regex: ' *\/\/ *([A-Za-z0-9_]*?).swift *\n *\/\/ *\1 *\n'
message: "Incorrect header comment package name"
@drewolbrich
drewolbrich / UIColor+Blended.swift
Last active December 4, 2024 21:40
Blends together two UIColors, returning a dynamic color
import UIKit
extension UIColor {
/// Creates a dynamic color from the receiver blended with another color.
///
/// If `weight` is 0, the color of `self` is returned. If `weight` is 1, the color
/// of `otherColor` is returned.
///
/// This method works correctly with light and dark mode. A dynamic color is
@drewolbrich
drewolbrich / UIColor+Attenuated.swift
Created December 12, 2021 18:48
Attenuates a UIColor, returning a dynamic color
import UIKit
extension UIColor {
/// Creates a dynamic color from the receiver with attenuated brightness.
///
/// This method works correctly with light and dark mode. A dynamic color is
/// returned, so if the user switches to dark mode, the attenuated dark mode version of `self`
/// will be displayed.
func attenuated(by attenuation: CGFloat) -> UIColor {
@drewolbrich
drewolbrich / CommonProfile.metal
Created April 18, 2022 21:05 — forked from warrenm/CommonProfile.metal
SceneKit's CommonProfile Shader v2 (macOS 10.15)
////////////////////////////////////////////////
// CommonProfile Shader v2
#import <metal_stdlib>
using namespace metal;
#ifndef __SCNMetalDefines__
#define __SCNMetalDefines__
@drewolbrich
drewolbrich / Entity+EnumerateHierarchy.swift
Last active August 2, 2024 21:32
A RealityKit Entity extension that enumerates the entities in a hierarchy
//
// Entity+EnumerateHierarchy.swift
//
// Created by Drew Olbrich on 7/18/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 / Entity+LoadFileAsync.swift
Last active August 7, 2024 23:51
A wrapper around iOS Entity/loadAsync(named:in:) and visionOS Entity(named:in:) async that works on both platforms
//
// Entity+LoadFileAsync.swift
//
// Created by Drew Olbrich on 8/4/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 / Entity+GenerateGroundingShadowComponents.swift
Last active March 6, 2024 15:48
Add GroundingShadowComponent to all model entities in a hierarchy
//
// Entity+GenerateGroundingShadowComponents.swift
//
// Created by Drew Olbrich on 10/18/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 / OpacityEntity.swift
Last active June 10, 2024 16:41
An entity that supports animated changes in opacity
import Foundation
import RealityKit
// ***********************************************************************
// Important: You may want to use this newer `Entity` extension instead,
// which includes a completion handler for the `Entity/setOpacity` method:
// https://gist.github.com/drewolbrich/1e9d3da074c8a1d5ca93721124b97596
// ***********************************************************************
extension Entity {
@drewolbrich
drewolbrich / Entity+Opacity.swift
Last active March 6, 2025 03:09
An Entity extension that supports animated changes the opacity of an entity and its descendants
//
// Entity+Opacity.swift
//
// Created by Drew Olbrich on 10/25/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 / SIMD+LookAt.swift
Last active August 11, 2024 03:43
SIMD look-at functions
//
// SIMD+LookAt.swift
//
// Created by Drew Olbrich on 11/10/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