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 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) { |
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 | |
// https://nilcoalescing.com/blog/ | |
@available(iOS 18.0, *) | |
struct RecyclingScrollingLazyView< | |
ID: Hashable, Content: View | |
>: View { | |
let rowIDs: [ID] | |
let rowHeight: CGFloat | |
@ViewBuilder |
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
// | |
// YelpApiService.swift | |
// Foodee | |
// | |
// Created by Gary Tokman on 9/21/21. | |
// | |
import Combine | |
import CoreLocation | |
import Foundation |
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 ContentView: View { | |
let viewModel: ViewModel | |
@State var businesses = [Business]() | |
var body: some View { | |
NavigationView { | |
ZStack { | |
if businesses.isEmpty { | |
ProgressView("Loading...") | |
} |
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 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()) |
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
/// 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() |
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
extension YelpEndpoint { | |
/// Endpoint URL Path | |
var path: String { | |
switch self { | |
case .search: | |
return "/v3/businesses/search" | |
case let .detail(id): | |
return "/v3/businesses/\(id)" | |
} | |
} |
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 CoreLocation | |
/// Endpoints for Yelp | |
enum YelpEndpoint { | |
case search(term: String, location: CLLocation) | |
case detail(id: String) | |
} |
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
Task { | |
let (data, _) = try! await session.data(for: request) | |
let result = try! JSONDecoder().decode(SearchResult.self, from: data) | |
self.businesses = result.businesses | |
} |
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
NavigationView { | |
List { | |
ForEach(businesses) { business in | |
Text(business.name) | |
} | |
} | |
.listStyle(.plain) | |
.navigationTitle(Text("Boston")) | |
.refreshable { | |
// do something |
NewerOlder