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 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
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
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
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
// 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
import SwiftUI | |
protocol TXTabBarElementView: View { | |
associatedtype Content | |
var content: Content { get set } | |
var item: TXTabItem.Item { get set } | |
} | |
public struct TXTabItem: TXTabBarElementView { |
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 TestPaginationView: View { | |
//1 | |
@ObservedObject var viewModel = ItemListViewModel() | |
var body: some View { | |
NavigationView { | |
//2 | |
ListPagination(items: viewModel.items, offset: 8, pagination: viewModel.getData) { item in | |
//3 | |
Text("Item #\(item)") |
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
//1 | |
class ItemListViewModel: ObservableObject { | |
//2 | |
@Published var items: [Int] = [] | |
//3 | |
static private var itemsPerPage = 25 | |
private var start = -ItemListViewModel.itemsPerPage | |
private var stop = -1 | |
private let maxData = 250 |
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 | |
public struct SpinnerView: UIViewRepresentable { | |
public typealias UIViewType = UIActivityIndicatorView | |
public init(isAnimating: Binding<Bool>, style: UIActivityIndicatorView.Style) { | |
self._isAnimating = isAnimating | |
self.style = style | |
} | |