This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct BackgroundGradientView: View { | |
let color: Color | |
var body: some View { | |
ZStack { | |
Color.black | |
.ignoresSafeArea() | |
LinearGradient( | |
gradient: Gradient( | |
colors: [ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// GesturesDemo.swift | |
// DragGesture_SwiftUI | |
// | |
// Created by Pedro Rojas on 10/01/22. | |
// | |
// See the full video here: https://youtu.be/muHDX4ij_EQ | |
import SwiftUI |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
protocol Animal { | |
associatedtype CommodityType: Food | |
associatedtype FeedType: AnimalFeed | |
var isHungry: Bool { get } | |
func produce() -> CommodityType | |
func eat(_: FeedType) |