Skip to content

Instantly share code, notes, and snippets.

View pitt500's full-sized avatar

Pedro Rojas pitt500

View GitHub Profile
private func isLastItem(index: Int) -> Bool {
index == (items.count - 1)
}
private func isOffsetReached(at index: Int) -> Bool {
index == (items.count - offset)
}
private func itemAppears(at index: Int) {
if isOffsetReached(at: index) {
var pagination: ((() -> Void)?) -> Void
@State var isLoading = false
private var offset: Int
public struct ListPagination<Item: Identifiable, Content: View>: View {
private var items: [Item]
var content: (_ item: Item) -> Content
public init (items: [Item], offset: Int = 5,
pagination: @escaping (_ completion: (() -> Void)?) -> Void,
@ViewBuilder content: @escaping (_ item: Item) -> Content) {
self.items = items
self.content = content
self.pagination = pagination
self.offset = offset
}
public var body: some View {
List {
//1.
ForEach(items.indices, id: \.self) { index in
VStack {
//2.
self.content(self.items[index])
//3.
if self.isLoading && self.isLastItem(index: index) {
@pitt500
pitt500 / GetNearestDegree.swift
Created May 29, 2020 18:21
Given a clock time in hh:mm format, determine, to the nearest degree, the angle between the hour and the minute hands.
func getNearestDegree(time: String) -> Int {
let array = time.split(separator: ":")
let hours = Int(array[0])!
let minutes = Int(array[1])!
let hourPosition = hours*60 + minutes
let minutesPosition = 12*minutes
let actualPosition = hourPosition - minutesPosition
let degrees = actualPosition/2