Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed deprecated types #2

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions ProductFetcher.swift
Original file line number Diff line number Diff line change
@@ -26,13 +26,13 @@ enum FetchError: Error {
}
}

class ProductFetcher: BindableObject {
class ProductFetcher: ObservableObject {
private static let apiUrlString = "https://gist.githubusercontent.com/schmidyy/02fdec9b9e05a71312a550fc50f948e6/raw/7fc2facbbf9c3aa526f35a32d0c7fe74a4fc29a1/products.json"
var didChange = PassthroughSubject<ProductFetcher, Never>()
var objectWillChange = PassthroughSubject<ProductFetcher, Never>()

var state: LoadableState<Root> = .loading {
didSet {
didChange.send(self)
objectWillChange.send(self)
}
}

@@ -61,12 +61,12 @@ class ProductFetcher: BindableObject {
}
}

class ImageFetcher: BindableObject {
var didChange = PassthroughSubject<Data, Never>()
class ImageFetcher: ObservableObject {
var objectWillChange = PassthroughSubject<Data, Never>()

var data: Data = Data() {
didSet {
didChange.send(data)
objectWillChange.send(data)
}
}

4 changes: 2 additions & 2 deletions ProductListView.swift
Original file line number Diff line number Diff line change
@@ -9,7 +9,7 @@
import SwiftUI

struct ProductListView : View {
@ObjectBinding var productFetcher = ProductFetcher()
@ObservedObject var productFetcher = ProductFetcher()

private var stateContent: AnyView {
switch productFetcher.state {
@@ -26,7 +26,7 @@ struct ProductListView : View {
case .success(let root):
return AnyView(
List(root.products) { product in
NavigationButton(destination: ProductDetailsView(product: product)) {
NavigationLink(destination: ProductDetailsView(product: product)) {
ProductRow(product: product)
}
}
10 changes: 6 additions & 4 deletions Products/SceneDelegate.swift
Original file line number Diff line number Diff line change
@@ -20,10 +20,12 @@ class SceneDelegate: UIResponder, UIWindowSceneDelegate {
// This delegate does not imply the connecting scene or session are new (see `application:configurationForConnectingSceneSession` instead).

// Use a UIHostingController as window root view controller
let window = UIWindow(frame: UIScreen.main.bounds)
window.rootViewController = UIHostingController(rootView: ProductListView())
self.window = window
window.makeKeyAndVisible()
if let windowScene = scene as? UIWindowScene {
let window = UIWindow(windowScene: windowScene)
window.rootViewController = UIHostingController(rootView: ProductListView())
self.window = window
window.makeKeyAndVisible()
}
}

func sceneDidDisconnect(_ scene: UIScene) {
2 changes: 1 addition & 1 deletion Views.swift
Original file line number Diff line number Diff line change
@@ -21,7 +21,7 @@ struct ActivityIndicator: UIViewRepresentable {
}

struct LoadableImageView: View {
@ObjectBinding var imageFetcher: ImageFetcher
@ObservedObject var imageFetcher: ImageFetcher

init(with urlString: String) {
imageFetcher = ImageFetcher(url: urlString)