Skip to content

Instantly share code, notes, and snippets.

@PhilipDukhov
PhilipDukhov / ForEachIndexed.swift
Last active October 29, 2021 07:58
ForEachIndexed: ForEach enumerated to use index inside
struct ForEachIndexed<Data: RandomAccessCollection, Content: View, ID: Hashable>: View, DynamicViewContent where Data.Index: Hashable {
var data: [(Data.Index, Data.Element)] {
forEach.data
}
let forEach: ForEach<[(Data.Index, Data.Element)], ID, Content>
init(
_ data: Data,
id: KeyPath<Data.Element, ID>,
struct GradientTestView: View {
@State private var startPoint = UnitPoint(x: 0.762648, y: -0.376472566)
@State private var endPoint = UnitPoint(x: 0.812653333, y: 0.803190265)
let scale: CGFloat = 1.5
var body: some View {
ZStack {
GeometryReader { proxy in
let size = CGSize(
width: proxy.size.width / scale,
import Foundation
extension NSError {
convenience init(description: String, code: Int = 0) {
self.init(
domain: "plist script",
code: code,
userInfo: [NSLocalizedDescriptionKey: description]
)
}
@PhilipDukhov
PhilipDukhov / CALayer+animate.swift
Last active September 21, 2020 05:38
safe way to animate CALayer
import QuartzCore
extension CALayer {
struct Animation<Value> {
let keyPath: ReferenceWritableKeyPath<CALayer, Value>
let value: Value
let duration: TimeInterval
let timingFunction: CAMediaTimingFunction? = nil
let beginFromCurrentState = false
}