A little out of date but great conceptually:
Swift has computed properties; here's a pattern for caching them:
struct Cached <T, U> {
var value : T { willSet { _calculated = nil } }
private var _calculated : U? = nil
private var function : (T) -> U
init(_ value: T, _ f: (T) -> U) {
self.function = f
self.value = value
}
var calculated : U {
mutating get {
if _calculated == nil { _calculated = function(value) }
return _calculated!
}
}
}
Example use:
var a = Cached(0) {
(a: Int) -> Int in
print("did calculate")
return a + 100
}
// Prints "did calculate"
print(a.calculated)
// Prints "100"
a.value = 10
print(a.calculated)
// Prints "did calculate\n110"
https://www.swiftbysundell.com/articles/what-makes-code-swifty/ via https://news.ycombinator.com/item?id=22399082
https://news.ycombinator.com/item?id=25171532 (really about https://triplebyte.com/blog/should-i-use-swiftui-in-production-heres-how-to-decide?ref=hnpost which calls out a lot of the current shortcomings but still loves it)
But there is some built-in "hashable" protocol. From 2020 This appears to be for storing items in a dictionary.
Stanford course covering SwiftUI
Badly written article about vision framework/OCR. https://www.shawnbaek.com/posts/lets-make-a-receipt-text-recognizer-with-the-apple-vision-framework
https://github.com/STREGAsGate/GameMath Handy math https://www.reddit.com/r/swift/comments/mu6fpn/gamemath_for_swift_is_now_open_source/?utm_source=share&utm_medium=ios_app&utm_name=iossmf
Some guy's "game math" - from above, is for 3d. Not optimized, but maybe a relevant example of an approach to stuff you are interested in.