Skip to content

Instantly share code, notes, and snippets.

View JoshHrach's full-sized avatar
🏠
Working from home

Josh Hrach JoshHrach

🏠
Working from home
View GitHub Profile
@rnapier
rnapier / SelectorNotifiction.swift
Last active September 26, 2024 07:59
Musings on Notifications and Actors
/// Some exploration into how selector-based notification interact with actors.
///
/// Or in the words of Brent Simmons (@[email protected]),
/// "Selector-based Notification Observers Are Actually Good"
/// Overall, I'm reasonably convinced, in that it avoids the headaches of `deinit` in actors.
/// However, Combine-based observation is also good at this, so I don't yet have a strong opinion
/// about old-school selectors vs Combine beyond my usual nervousness around Combine.
/// Whether "I'd like to reduce Combine" is more or less powerful than "I'd like to reduce @objc"
/// is yet to be seen.
@IanKeen
IanKeen / Example.swift
Last active June 26, 2024 07:38
ObservableObjectContainer: Consolidate nested/child ObservableObjects into a single publisher, useful for 'parent' ObservableObjects
// Setup
class Child: ObservableObject {
@Published var value = ""
}
class Parent: ObservableObjectContainer {
let single = Child()
let array = [Child(), Child()]
func updateSingle() {
@IanKeen
IanKeen / FocusState.swift
Last active June 26, 2024 07:34
SwiftUI: FocusedState shim for < iOS15
import Combine
import SwiftUI
extension View {
public func focused<T>(file: StaticString = #file, _ state: FocusState<T>, equals value: T) -> some View {
modifier(FocusedModifier(state: state, id: value, file: file))
}
}
@propertyWrapper
@marcedwards
marcedwards / displaysizes.txt
Last active November 16, 2023 06:52
iPhone, iPad, and Apple Watch display sizes
### Points and display type
PPI is points per inch below, not pixels per inch. Not all models are listed, just the first model with a new display size. Diamond, RGB Stripe and Pentile RGB refer to the subpixel patterns.
iPhone 1 = 320×480 at 163PPI sRGB IPS LCD RGB Stripe
iPhone 4 = 320×480 at 163PPI sRGB IPS LCD RGB Stripe
iPhone 5 = 320×568 at 163PPI sRGB IPS LCD RGB Stripe
iPhone 6 = 375×667 at 163PPI sRGB IPS LCD RGB Stripe
iPhone 6 Plus = 414×736 at 153.5PPI sRGB IPS LCD RGB Stripe
iPhone 7 = 375×667 at 163PPI P3 IPS LCD RGB Stripe
import SwiftUI
struct HeroAnimationTest: View {
let indices = 0 ..< 3
@State
var showsOtherView = false
@Namespace
var namespaceID: Namespace.ID
@truizlop
truizlop / Wave.swift
Created September 10, 2020 14:41
Wave animation using SwiftUI
import SwiftUI
let LINE_LENGTH: Double = 500.0
let N = 720
let LINES = 18
let WAVES: Double = 18.0
let WAVE_HEIGHT: Double = 20
let SPACING: Double = 27.0
let CURL_AMOUNT: Double = 12.0
import SwiftUI
import PlaygroundSupport
struct Sunset: View {
@State var backgroundColor = Color.blue
@State var sunSetted = false
let sunGradient = [Color.yellow, Color.orange]
let moonGradient = [Color.gray, Color.black]
@State var alignment = Alignment.top
@DreamingInBinary
DreamingInBinary / Best in Class iOS Checklist
Last active October 14, 2024 16:16
This is a public checklist updated every year after the latest version of iOS and iPadOS are shipped. It's a boiled down version of a "Best in Class" app checklist created by Jordan Morgan.
# A Best in Class Checklist
A boiled down checklist adapted from this [post](https://www.swiftjectivec.com/a-best-in-class-app/), created by @jordanmorgan10.
> To use this, create a Github Issue in your own repo, and simply copy and paste this text.
## iOS Core Technology
_Things any iOS app can benefit from_
- [ ] iCloud Sync
- [ ] Focus Filter Support
@mergesort
mergesort / AnimationDemo.swift
Last active December 18, 2023 02:34
A SwiftUI prototype animation for adding/removing players from a game
import SwiftUI
let colors = [
Color.pink,
Color.blue,
Color.green,
Color.orange,
Color.purple,
Color.black,
]
//
// AnimatableVector2D.swift
//
// this is derivation of generic AnimatableVector presented at: https://nerdyak.tech/development/2020/01/12/animating-complex-shapes-in-swiftui.html
//
// Created by Pavel Zak on 18/05/2020.
//
import SwiftUI