Great series of short articles introducing Apple's Metal framework.
- 2022-04-01: Day 1: Devices
- 2022-04-02: Day 2: Buffers
- 2022-04-03: Day 3: Commands
- 2022-04-04: Day 4: MTKView
- 2022-04-05: Day 5: Shaders
- 2022-04-06: Day 6: Pipelines
| import SwiftUI | |
| struct Zoom: ViewModifier { | |
| @Binding var scale: CGFloat | |
| @Binding var position: CGPoint | |
| @State private var currentZoom: CGFloat = 0 | |
| private let scrollCoordinateSpace = "scroll" | |
Great series of short articles introducing Apple's Metal framework.
| import SwiftUI | |
| extension View { | |
| /// Proposes a percentage of its received proposed size to `self`. | |
| /// | |
| /// This modifier multiplies the proposed size it receives from its parent | |
| /// with the given factors for width and height. | |
| /// | |
| /// If the parent proposes `nil` or `.infinity` to us in any dimension, | |
| /// we’ll forward these values to our child view unchanged. |
| // | |
| // DebugDevice.swift | |
| // | |
| // Copyright 2022 • Sidetrack Tech Limited | |
| // | |
| import Foundation | |
| // This must be called on the main-thread. | |
| var isDebugProfileInstalled: Bool { |
| extension Image { | |
| /// This helps achieving what `UIView.ContentMode.scaleAspectFit` and `.scaleAspectFill` do in UIImageView.contentMode | |
| /// | |
| /// The difference between Image.containerAspectRatio (this) and SwiftUIs View.aspectRatio is that the first applies the | |
| /// aspect ratio to the view that contains the image, rather than to the image itself. | |
| /// | |
| /// So in the following example: | |
| /// - The first image will scale to a square but the contentMode does not do anything to prevent stretching and wether you use .fit or .fill does not matter. | |
| /// - The second image will resize to fit inside a square while maintaining its aspect ratio, similar to how a UIImageView with contentMode set to scaleAspectFit behaves. | |
| /// - The third image will resize to fill inside a square while maintaining its aspect ratio similar to how a UIImageView with contentMode set to scaleAspectFill behaves. |
| // | |
| // RoundedPolygon.swift | |
| // | |
| // Created by Nate on 2022-10-17. | |
| // | |
| import SwiftUI | |
| struct RoundedPolygon: Shape { | |
| extension AsyncSequence where Element: Hashable { | |
| /// Sequence that emits unique elements once each | |
| func unique() -> AsyncUniqueSequence<Self> { | |
| AsyncUniqueSequence(self) | |
| } | |
| } | |
| /// Sequence that only emits unique elements once. | |
| /// While iterating, all emitted elements are retained within a `Set` to ensure uniqueness of each element emitted. |
| #if canImport(SwiftUI) && DEBUG | |
| import SwiftUI | |
| struct DebugJsonView: View { | |
| let json: JsonElement | |
| init(_ json: String) { | |
| self.json = JsonElement.parse(json) |
| // | |
| // ContentView.swift | |
| // SwiftUIPlayground | |
| // | |
| // Created by BJ Homer on 4/26/21. | |
| // | |
| import SwiftUI | |
| import UIKit | |
| import AVFoundation | |
| class ViewController: UIViewController, UITableViewDelegate, UITableViewDataSource { | |
| let tableView = UITableView(frame: .zero, style: .plain) | |
| override func viewDidLoad() { | |
| super.viewDidLoad() | |
| tableView.register(PlayerTableViewCell.self, forCellReuseIdentifier: "PlayerCell") |