Skip to content

Instantly share code, notes, and snippets.

View pitt500's full-sized avatar

Pedro Rojas pitt500

View GitHub Profile
@pitt500
pitt500 / noSeparatorLinesInList.swift
Last active March 6, 2021 05:18
Method to hide default separator lines in a SwiftUI's List. You need to call it in the cell (as a modifier), not the list.
// Call this in the cell, for example CellView().noSeparators()
extension View {
@ViewBuilder public func noSeparators(
edgeInsets: EdgeInsets = EdgeInsets(top: 0, leading: 0, bottom: 0, trailing: 0),
color: Color
) -> some View {
self
.padding(edgeInsets)
.frame(
minWidth: 0,
@pitt500
pitt500 / SoccerPlayer.swift
Last active March 17, 2021 13:06
SoccerPlayer code requiered for video "Protocols in Swift Pt 2: Methods, initializers & extensions" https://youtu.be/qiMFIopQJME
protocol Player {
var name: String { get set }
var score: Int { get }
var nickname: String { get }
static var numberOfPlayers: Int { get set }
}
struct SoccerPlayer: Player {
var name: String
protocol Loggable {
init(filename: String)
func log()
}
class Logger: Loggable {
private var filename = ""
// Required is needed for subclass conforming protocol too.
// Unless class is marked as final
@pitt500
pitt500 / BackgroundGradientView.swift
Created March 27, 2021 23:27
Background with a soft gradient
struct BackgroundGradientView: View {
let color: Color
var body: some View {
ZStack {
Color.black
.ignoresSafeArea()
LinearGradient(
gradient: Gradient(
colors: [
@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 }
@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 / 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 / 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 / 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)
import Foundation
protocol Animal {
associatedtype CommodityType: Food
associatedtype FeedType: AnimalFeed
var isHungry: Bool { get }
func produce() -> CommodityType
func eat(_: FeedType)