This guide is adapted from this original post by Christopher Charles.
- Clone the MLX Swift Examples GitHub repository:
This guide is adapted from this original post by Christopher Charles.
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) | |
} |
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 } | |
) | |
} | |
// | |
// ContentView.swift | |
// GradientEffect | |
// | |
// Created by Christian Privitelli on 18/7/20. | |
// | |
import SwiftUI | |
struct ContentView: View { | |
// | |
// ContentView.swift | |
// TryGeometryReader | |
// | |
// Created by satoutakeshi on 2019/12/07. | |
// Copyright © 2019 satoutakeshi. Licensed under MIT. | |
// | |
import SwiftUI |
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 |
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 | |
// } |
/// 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 |
/** | |
* MacEditorTextView | |
* Copyright (c) Thiago Holanda 2020-2021 | |
* https://bsky.app/profile/tholanda.com | |
* | |
* (the twitter account is now deleted, please, do not try to reach me there) | |
* https://twitter.com/tholanda | |
* | |
* MIT license | |
*/ |
import SwiftUI | |
struct ContentView : View { | |
var body: some View { | |
PKCanvasRepresentation() | |
} | |
} | |
#if DEBUG | |
struct ContentView_Previews : PreviewProvider { |