Skip to content

Instantly share code, notes, and snippets.

View pitt500's full-sized avatar

Pedro Rojas pitt500

View GitHub Profile
import SwiftUI
struct ContentView: View {
@State var path = NavigationPath()
var body: some View {
NavigationStack(path: $path) {
List {
import SwiftUI
struct ContentView: View {
@State private var path: [Fruit] = []
var body: some View {
NavigationStack(path: $path) {
List {
NavigationLink(Fruit.apple.name, value: Fruit.apple)
import SwiftUI
struct ContentView: View {
@State private var path: [Fruit] = []
var body: some View {
NavigationStack(path: $path) {
List {
NavigationLink(Fruit.apple.name, value: Fruit.apple)
@pitt500
pitt500 / NavigationStack_CustomBackButton.swift
Last active July 8, 2022 04:43
Demo showing a custom back button implemented using SwiftUI's NavigationStack
import SwiftUI
struct ContentView: View {
@State private var path: [Fruit] = []
var body: some View {
NavigationStack(path: $path) {
List {
NavigationLink(Fruit.apple.name, value: Fruit.apple)
import Foundation
protocol Animal {
associatedtype CommodityType: Food
associatedtype FeedType: AnimalFeed
var isHungry: Bool { get }
func produce() -> CommodityType
func eat(_: FeedType)
@pitt500
pitt500 / SwiftLogo.swift
Created March 4, 2022 18:37
If you want to know the details of this implementation, check out this video 👉🏻 https://youtu.be/8vAJ9x0z4k8
import SwiftUI
struct SwiftLogo: Shape {
func path(in rect: CGRect) -> Path {
var path = Path()
let width = rect.width
let height = rect.height
let startPoint = CGPoint(x: rect.minX, y: height * 0.63)
@pitt500
pitt500 / MagnificationGestureDemo.swift
Last active March 16, 2022 14:19
Magnification gesture demo made in SwiftUI. Check out all the details of this code in this video: https://youtu.be/Gq39U4mJEY4
import SwiftUI
struct ImageDetailView: View {
let image: Image
@State var scale = 1.0
@State private var lastScale = 1.0
private let minScale = 1.0
private let maxScale = 5.0
var magnification: some Gesture {
@pitt500
pitt500 / TapGestureDemo.swift
Created January 28, 2022 15:22
Tap Gesture demo. Check out all the details here: https://youtu.be/90NcdAV0gPg
import SwiftUI
struct ContentView: View {
@GestureState var anotherState = false
@State var isTapped = false
var tap: some Gesture {
TapGesture(count: 4)
.onEnded { state in
// State is an empty tuple (void)
@pitt500
pitt500 / DragGestureDemo.swift
Last active January 15, 2022 22:19
DragGesture demo showed in Swift and Tip: https://youtu.be/muHDX4ij_EQ
//
// GesturesDemo.swift
// DragGesture_SwiftUI
//
// Created by Pedro Rojas on 10/01/22.
//
// See the full video here: https://youtu.be/muHDX4ij_EQ
import SwiftUI
@pitt500
pitt500 / GenericsAssociatedTypes.swift
Last active April 2, 2021 20:06
Code made in Swift and Tips for episode "Generics in Swift: Protocols with associated types" https://youtu.be/pp4hKZBBci4
import Foundation
// MARK: - Associated Types
// Placeholder name to a type that is used as part of a protocol.
// The actual type for the associated type isn't specified until the protocol is adopted.
// Use associatedtype keyword
protocol Stack {
associatedtype Element
var count: Int { get }