This file contains 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
func mostRecentWorkouts(for healthStore: HKHealthStore, limit: Int) async throws -> [HKWorkout] { | |
let query = HKSampleQueryDescriptor( | |
predicates: [.workout()], | |
sortDescriptors: [SortDescriptor(\.endDate, order: .reverse)], | |
limit: limit | |
) | |
return try await query.result(for: healthStore) | |
} |
This file contains 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
class ExpansionHandler<T: Equatable>: ObservableObject { | |
@Published private (set) var expandedItem: T? | |
func isExpanded(_ item: T) -> Binding<Bool> { | |
return Binding( | |
get: { item == self.expandedItem }, | |
set: { self.expandedItem = $0 == true ? item : nil } | |
) | |
} |
This file contains 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
// | |
// ContentView.swift | |
// GradientEffect | |
// | |
// Created by Christian Privitelli on 18/7/20. | |
// | |
import SwiftUI | |
struct ContentView: View { | |
This file contains 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
// | |
// ContentView.swift | |
// TryGeometryReader | |
// | |
// Created by satoutakeshi on 2019/12/07. | |
// Copyright © 2019 satoutakeshi. Licensed under MIT. | |
// | |
import SwiftUI |
This file contains 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 | |
enum Message { | |
/// A message and OK button | |
case information(body: String) | |
/// A message and OK button | |
case warning(body: String) | |
/// A question with YES and NO buttons | |
case confirmation(body: String, action: () -> Void) | |
/// A question about destractive action with `action` and CANCEL buttons |
This file contains 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 HorizontalList<Item, Card, Detail>: View where Item: NSManagedObject, Card: View, Detail: View{ | |
var items: FetchedResults<Item> | |
var card: (Item) -> Card | |
var detail: (Item) -> Detail | |
// init(items: FetchedResults<Item>, @ViewBuilder card: @escaping (Item) -> Card, @ViewBuilder detail: @escaping (Item) -> Detail) { | |
// self.items = items | |
// self.card = card | |
// self.detail = detail | |
// } |
This file contains 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
/// An iOS style TabView that doesn't reset it's childrens navigation stacks when tabs are switched. | |
public struct UIKitTabView: View { | |
private var viewControllers: [UIHostingController<AnyView>] | |
private var selectedIndex: Binding<Int>? | |
@State private var fallbackSelectedIndex: Int = 0 | |
public init(selectedIndex: Binding<Int>? = nil, @TabBuilder _ views: () -> [Tab]) { | |
self.viewControllers = views().map { | |
let host = UIHostingController(rootView: $0.view) | |
host.tabBarItem = $0.barItem |
This file contains 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
/** | |
* MacEditorTextView | |
* Copyright (c) Thiago Holanda 2020-2021 | |
* https://twitter.com/tholanda | |
* | |
* MIT license | |
*/ | |
import Combine | |
import SwiftUI |
This file contains 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 { | |
var body: some View { | |
PKCanvasRepresentation() | |
} | |
} | |
#if DEBUG | |
struct ContentView_Previews : PreviewProvider { |
This file contains 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 | |
/// Example of how to get Dynamic Type with custom fonts in SwiftUI. | |
struct ContentView: View { | |
var body: some View { | |
VStack(spacing: 20) { | |
Text("A large title").customFont(.largeTitle) // "Optima-ExtraBlack", 28 | |
Text("A body").customFont(.body) // "Kailasa", 16 | |
Text("A caption").customFont(.caption2) // "IowanOldStyle-Italic", 11 | |
} |
NewerOlder