Skip to content

Instantly share code, notes, and snippets.

View gtokman's full-sized avatar
🏴‍☠️
Focusing

Gary Tokman gtokman

🏴‍☠️
Focusing
View GitHub Profile
import SwiftUI
struct ContentView: View {
var response: LooksResponse {
try! LooksResponse.decode()
}
@State var isFullScreen = false
//
// ContentView.swift
// MessageMenu
//
// Created by Gary Tokman on 5/25/25.
//
import SwiftUI
struct ContentView: View {
import SwiftUI
import MarkdownUI
import Splash
@available(iOS 18.0, *)
struct Think: View {
@Environment(\.colorScheme) private var colorScheme
@Namespace private var ns
@State private var position = ScrollPosition(edge: .top)
import SwiftUI
struct Marquee<Content: View>: View {
@ViewBuilder var content: Content
@State private var containerWidth: CGFloat? = nil
@State private var model: MarqueeModel
private var targetVelocity: Double
private var spacing: CGFloat
init(targetVelocity: Double, spacing: CGFloat = 10, @ViewBuilder content: () -> Content) {
@gtokman
gtokman / RecyclingScrollingLazyView.swift
Created March 9, 2025 15:22
RecyclingScrollingLazyView
import SwiftUI
// https://nilcoalescing.com/blog/
@available(iOS 18.0, *)
struct RecyclingScrollingLazyView<
ID: Hashable, Content: View
>: View {
let rowIDs: [ID]
let rowHeight: CGFloat
@ViewBuilder
//
// YelpApiService.swift
// Foodee
//
// Created by Gary Tokman on 9/21/21.
//
import Combine
import CoreLocation
import Foundation
struct ContentView: View {
let viewModel: ViewModel
@State var businesses = [Business]()
var body: some View {
NavigationView {
ZStack {
if businesses.isEmpty {
ProgressView("Loading...")
}
struct ViewModel {
let apiService: ApiService
let locationService: LocationService // fetch location data
/// Fetch businesses from service for term
func getBusinesses(for term: String) async throws -> [Business] {
return try
await apiService
.businesses(
.search(term: term, location: locationService.current())
/// Fetch API data for `Endpoint`
struct ApiService {
let businesses: (YelpEndpoint) async throws -> [Business]
}
extension ApiService {
/// Live service used in App
static let live = ApiService { endpoint in
let (data, error) = try await URLSession.shared.data(for: endpoint.request)
let decoder = JSONDecoder()
extension YelpEndpoint {
/// Endpoint URL Path
var path: String {
switch self {
case .search:
return "/v3/businesses/search"
case let .detail(id):
return "/v3/businesses/\(id)"
}
}