Share
Embed
Transcript
143 slides
-
͢͜ͱ w ඇಉظॲཧσʔλͷঢ়ଶཧํ๏Λ༷ʑͳ༷Λݩʹ࣮ɾߟ w ख๏ w FOVNΛ༻͍ͨख๏ w ίϯϙʔωϯτΛ༻͍ͨख๏ w
ओޠ͕େ͖͍ςʔϚͳͷͰɺߟ͑ํͷҰͭͱͯ͠ଊ͑ͭͭ վળ৽ͨͳࢹ͕͋Ε࣭ɾίϝϯτ͚ͨΒخ͍͠Ͱ͢👍 -
$BTFFOVNͷಋೖ#FGPSF ঢ়ଶͷએݴ @State private var data: User? @State private var
error: (any Error)? @State private var isLoading = false -
$BTFFOVNͷಋೖ#FGPSF 7JFXͷग़͠Θ͚ var body: some View { List { if
isLoading { EmptyView() } else { if let data { content(user: data) } else if error != nil { ErrorStateView() } } } .overlay { if isLoading { ProgressView() } } } -
$BTFFOVNͷಋೖ#FGPSF var body: some View { List { if isLoading
{ EmptyView() } else { if let data { content(user: data) } else if error != nil { ErrorStateView() } } } .overlay { if isLoading { ProgressView() } } } ϩʔυத 7JFXͷग़͠Θ͚ -
$BTFFOVNͷಋೖ#FGPSF var body: some View { List { if isLoading
{ EmptyView() } else { if let data { content(user: data) } else if error != nil { ErrorStateView() } } } .overlay { if isLoading { ProgressView() } } } ϩʔυத ޭ 7JFXͷग़͠Θ͚ -
$BTFFOVNͷಋೖ#FGPSF var body: some View { List { if isLoading
{ EmptyView() } else { if let data { content(user: data) } else if error != nil { ErrorStateView() } } } .overlay { if isLoading { ProgressView() } } } ϩʔυத ޭ ࣦഊ 7JFXͷग़͠Θ͚ -
$BTFFOVNͷಋೖ#FGPSF ঢ়ଶͷૢ࡞ʢඇಉظॲཧʣ func fetchUser() async { if isLoading { return
} isLoading = true data = nil error = nil do { data = try await API.getUser() } catch { self.error = error } isLoading = false } -
$BTFFOVNͷಋೖ#FGPSF ঢ়ଶͷૢ࡞ʢඇಉظॲཧʣ func fetchUser() async { if isLoading { return
} isLoading = true data = nil error = nil do { data = try await API.getUser() } catch { self.error = error } isLoading = false } ϩʔυ։࢝ -
$BTFFOVNͷಋೖ#FGPSF ঢ়ଶͷૢ࡞ʢඇಉظॲཧʣ func fetchUser() async { if isLoading { return
} isLoading = true data = nil error = nil do { data = try await API.getUser() } catch { self.error = error } isLoading = false } "1*Λୟ͘ ϩʔυ։࢝ -
$BTFFOVNͷಋೖ#FGPSF ঢ়ଶͷૢ࡞ʢඇಉظॲཧʣ func fetchUser() async { if isLoading { return
} isLoading = true data = nil error = nil do { data = try await API.getUser() } catch { self.error = error } isLoading = false } "1*Λୟ͘ ࣦഊͳΒFSSPS ϩʔυ։࢝ -
$BTFFOVNͷಋೖ#FGPSF ঢ়ଶͷૢ࡞ʢඇಉظॲཧʣ func fetchUser() async { if isLoading { return
} isLoading = true data = nil error = nil do { data = try await API.getUser() } catch { self.error = error } isLoading = false } "1*Λୟ͘ ࣦഊͳΒFSSPS ϩʔυऴྃ ϩʔυ։࢝ -
$BTFFOVNͷಋೖ#FGPSF JGͷωετ var body: some View { List { if
isLoading { EmptyView() } else { if let data { content(user: data) } else if error != nil { ErrorStateView() } } } .overlay { if isLoading { ProgressView() } } } ωετ͕ਂ͍ -
$BTFFOVNͷಋೖ#FGPSF มΛผʑʹૢ࡞͢Δͷ͕ࡶ func fetchUser() async { if isLoading { return
} isLoading = true data = nil error = nil do { data = try await API.getUser() } catch { self.error = error } isLoading = false } લճͷঢ়ଶΛআ -
$BTFFOVNͷಋೖ#FGPSF มΛผʑʹૢ࡞͢Δͷ͕ࡶ func fetchUser() async { if isLoading { return
} isLoading = true data = nil error = nil do { data = try await API.getUser() } catch { self.error = error } isLoading = false } ݁Ռͷೖͱ ϩʔυऴ͕ྃಠཱ લճͷঢ়ଶΛআ -
$BTFFOVNͷಋೖ"GUFS ঢ়ଶͷએݴ enum DataState<V, E: Error> { case idle case
loading case success(V) case failure(E) } @State private var dataState: DataState<User, any Error> = .idle -
$BTFFOVNͷಋೖ"GUFS ঢ়ଶͷએݴ enum DataState<V, E: Error> { case idle case
loading case success(V) case failure(E) } @State private var dataState: DataState<User, any Error> = .idle ม͕ͭ -
$BTFFOVNͷಋೖ"GUFS 7JFXͷग़͠Θ͚ var body: some View { List { switch
dataState { case .idle, .loading: EmptyView() case .success(let value): content(user: value) case .failure: ErrorStateView() } } .overlay { if dataState.isLoading { ProgressView() } } } -
$BTFFOVNͷಋೖ"GUFS 7JFXͷग़͠Θ͚ var body: some View { List { switch
dataState { case .idle, .loading: EmptyView() case .success(let value): content(user: value) case .failure: ErrorStateView() } } .overlay { if dataState.isLoading { ProgressView() } } } ωετ͕ͭ -
$BTFFOVNͷಋೖ"GUFS 7JFXͷग़͠Θ͚ var body: some View { List { switch
dataState { case .idle, .loading: EmptyView() case .success(let value): content(user: value) case .failure: ErrorStateView() } } .overlay { if dataState.isLoading { ProgressView() } } } extension DataState { var isLoading: Bool { if case .loading = self { return true } return false } } -
$BTFFOVNͷಋೖ"GUFS ঢ়ଶͷૢ࡞ʢඇಉظॲཧʣ func fetchUser() async { if dataState.isLoading { return
} dataState = .loading do { dataState = .success(try await API.getUser()) } catch { dataState = .failure(error) } } -
$BTFFOVNͷಋೖ"GUFS ঢ়ଶͷૢ࡞ʢඇಉظॲཧʣ func fetchUser() async { if dataState.isLoading { return
} dataState = .loading do { dataState = .success(try await API.getUser()) } catch { dataState = .failure(error) } } લճͷঢ়ଶআ JT-PBEJOHGBMTF ෆཁ -
$BTF࠶ಡΈࠐΈதσʔλΛදࣔ#FGPSF $BTFͷFOVNͰ࣮ enum DataState<V, E: Error> { case idle case
loading case success(V) case failure(E) } @State private var dataState: DataState<User, any Error> = .idle -
var body: some View { List { switch dataState {
case .idle, .loading: EmptyView() case .success(let value): content(user: value) case .failure: ErrorStateView() } } .overlay { if dataState.isLoading { ProgressView() } } } $BTF࠶ಡΈࠐΈதσʔλΛදࣔ#FGPSF $BTFͷFOVNͰ࣮ -
var body: some View { List { switch dataState {
case .idle, .loading: EmptyView() case .success(let value): content(user: value) case .failure: ErrorStateView() } } .overlay { if dataState.isLoading { ProgressView() } } } $BTF࠶ಡΈࠐΈதσʔλΛදࣔ#FGPSF $BTFͷFOVNͰ࣮ ɾϩʔυதͩͱσʔλ͕ফ͑Δ ɾϓϧϦϑͱೋॏʹϩʔυ͕දࣔ -
var body: some View { List { switch dataState {
case .idle, .loading: EmptyView() case .success(let value): content(user: value) case .failure: ErrorStateView() } } .overlay { if dataState.isLoading { ProgressView() } } } $BTF࠶ಡΈࠐΈதσʔλΛදࣔ#FGPSF $BTFͷFOVNͰ࣮ MPBEJOHʹ σʔλ͕ͳ͍ -
$BTF࠶ಡΈࠐΈதσʔλΛදࣔ"GUFS SF-PBEJOH 7 ΛՃ enum DataState<V, E: Error> { case
idle case loading case success(V) case failure(E) } @State private var dataState: DataState<User, any Error> = .idle -
$BTF࠶ಡΈࠐΈதσʔλΛදࣔ"GUFS SF-PBEJOH 7 ΛՃ enum DataState<V, E: Error> { case
idle case loading case reLoading(V) case success(V) case failure(E) } @State private var dataState: DataState<User, any Error> = .idle -
$BTF࠶ಡΈࠐΈதσʔλΛදࣔ"GUFS SF-PBEJOH 7 ΛՃ enum DataState<V, E: Error> { case
idle case initialLoading case reLoading(V) case success(V) case failure(E) } @State private var dataState: DataState<User, any Error> = .idle -
$BTF࠶ಡΈࠐΈதσʔλΛදࣔ"GUFS 7JFXͷग़͠Θ͚ var body: some View { List { switch
dataState { case .idle, .loading: EmptyView() case .success(let value): content(user: value) case .failure: ErrorStateView() } } .overlay { if dataState.isInitialLoading { ProgressView() } } } -
$BTF࠶ಡΈࠐΈதσʔλΛදࣔ"GUFS 7JFXͷग़͠Θ͚ var body: some View { List { switch
dataState { case .idle, .initialLoading: EmptyView() case .success(let value), .reLoading(let value): content(user: value) case .failure: ErrorStateView() } } .overlay { if dataState.isInitialLoading { ProgressView() } } } ࠶ಡΈࠐΈத σʔλΛදࣔ -
func fetchUser() async { if dataState.isLoading { return } dataState
= .loading do { dataState = .success(try await API.getUser()) } catch { dataState = .failure(error) } } $BTF࠶ಡΈࠐΈதσʔλΛදࣔ"GUFS ঢ়ଶૢ࡞ -
$BTF࠶ಡΈࠐΈதσʔλΛදࣔ"GUFS ঢ়ଶૢ࡞ func fetchUser() async { switch dataState { case
.idle, .failure: dataState = .initialLoading case .success(let value): dataState = .reLoading(value) case .initialLoading, .reLoading: return } do { dataState = .success(try await API.getUser()) } catch { dataState = .failure(error) } } -
$BTF࠶ಡΈࠐΈதσʔλΛදࣔ"GUFS ঢ়ଶૢ࡞ func fetchUser() async { switch dataState { case
.idle, .failure: dataState = .initialLoading case .success(let value): dataState = .reLoading(value) case .initialLoading, .reLoading: return } do { dataState = .success(try await API.getUser()) } catch { dataState = .failure(error) } } TVDDFTT͔Βϩʔυ͢Δ࣌ SF-PBEJOH -
$BTF࠶ಡΈࠐΈதσʔλΛදࣔ"GUFS ঢ়ଶૢ࡞ func fetchUser() async { if dataState.isLoading { return
} dataState.startLoading() do { dataState = .success(try await API.getUser()) } catch { dataState = .failure(error) } } extension DataState { mutating func startLoading() { switch self { case .idle, .failure: self = .initialLoading case .success(let value): self = .reLoading(value) default: return } } } -
$BTF࠶ಡΈࠐΈதσʔλΛදࣔ"GUFS ঢ়ଶૢ࡞ func fetchUser() async { if dataState.isLoading { return
} dataState.startLoading() do { dataState = .success(try await API.getUser()) } catch { dataState = .failure(error) } } -
$BTF࠶ಡΈࠐΈதσʔλΛදࣔ"GUFS ࣮ྃ var body: some View { List { switch
dataState { case .idle, .initialLoading: EmptyView() case .success(let value), .reLoading(let value): content(user: value) case .failure: ErrorStateView() } } .overlay { if dataState.isInitialLoading { ProgressView() } } } -
$BTF࠶ಡΈࠐΈதͰΤϥʔΛදࣔ#FGPSF $BTFͷFOVNͰ࣮ enum DataState<V, E: Error> { case idle case
initialLoading case reLoading(V) case success(V) case failure(E) } @State private var dataState: DataState<User, any Error> = .idle -
$BTF࠶ಡΈࠐΈதͰΤϥʔΛදࣔ#FGPSF $BTFͷFOVNͰ࣮ var body: some View { List { switch
dataState { case .idle, .initialLoading: EmptyView() case .success(let value), .reLoading(let value): content(user: value) case .failure: ErrorStateView() } } .overlay { if dataState.isInitialLoading { ProgressView() } } } -
$BTF࠶ಡΈࠐΈதͰΤϥʔΛදࣔ#FGPSF $BTFͷFOVNͰ࣮ var body: some View { List { switch
dataState { case .idle, .initialLoading: EmptyView() case .success(let value), .reLoading(let value): content(user: value) case .failure: ErrorStateView() } } .overlay { if dataState.isInitialLoading { ProgressView() } } } ɾϩʔυதͩͱΤϥʔ͕ফ͑Δ ɾϓϧϦϑͱೋॏʹϩʔυ͕දࣔ -
$BTF࠶ಡΈࠐΈதͰΤϥʔΛදࣔ#FGPSF $BTFͷFOVNͰ࣮ var body: some View { List { switch
dataState { case .idle, .initialLoading: EmptyView() case .success(let value), .reLoading(let value): content(user: value) case .failure: ErrorStateView() } } .overlay { if dataState.isInitialLoading { ProgressView() } } } JOJUJBM-PBEJOHʹΤϥʔ͕ͳ͍ -
$BTF࠶ಡΈࠐΈதͰΤϥʔΛදࣔ"GUFS SFUSZ-PBEJOH & ΛՃ enum DataState<V, E: Error> { case
idle case initialLoading case reLoading(V) case success(V) case failure(E) } @State private var dataState: DataState<User, any Error> = .idle -
$BTF࠶ಡΈࠐΈதͰΤϥʔΛදࣔ"GUFS SFUSZ-PBEJOH & ΛՃ enum DataState<V, E: Error> { case
idle case initialLoading case reLoading(V) case retryLoading(E) case success(V) case failure(E) } @State private var dataState: DataState<User, any Error> = .idle -
var body: some View { List { switch dataState {
case .idle, .initialLoading: EmptyView() case .success(let value), .reLoading(let value): content(user: value) case .failure: ErrorStateView() } } .overlay { if dataState.isInitialLoading { ProgressView() } } } $BTF࠶ಡΈࠐΈதͰΤϥʔΛදࣔ"GUFS 7JFXͷग़͠Θ͚ -
$BTF࠶ಡΈࠐΈதͰΤϥʔΛදࣔ"GUFS 7JFXͷग़͠Θ͚ var body: some View { List { switch
dataState { case .idle, .initialLoading: EmptyView() case .success(let value), .reLoading(let value): content(user: value) case .failure, .retryLoading: ErrorStateView() } } .overlay { if dataState.isInitialLoading { ProgressView() } } } ࠶ಡΈࠐΈத ΤϥʔΛදࣔ -
$BTF࠶ಡΈࠐΈதͰΤϥʔΛදࣔ"GUFS ঢ়ଶૢ࡞ func fetchUser() async { if dataState.isLoading { return
} dataState.startLoading() do { dataState = .success(try await API.getUser()) } catch { dataState = .failure(error) } } -
$BTF࠶ಡΈࠐΈதͰΤϥʔΛදࣔ"GUFS ঢ়ଶૢ࡞ func fetchUser() async { if dataState.isLoading { return
} dataState.startLoading() do { dataState = .success(try await API.getUser()) } catch { dataState = .failure(error) } } extension DataState { mutating func startLoading() { switch self { case .idle: self = .initialLoading case .success(let value): self = .reLoading(value) case .failure(let error): self = .retryLoading(error) default: return } } } GBJMVSF͔Βϩʔυ͢Δ࣌ SFUSZ-PBEJOH -
$BTF࠶ಡΈࠐΈதͰΤϥʔΛදࣔ"GUFS ࣮ྃ var body: some View { List { switch
dataState { case .idle, .initialLoading: EmptyView() case .success(let value), .reLoading(let value): content(user: value) case .failure, .retryLoading: ErrorStateView() } } .overlay { if dataState.isInitialLoading { ProgressView() } } } -
ঢ়ଶ͕૿͑ͯෳࡶʹͳͬͨʁ enum DataState<V, E: Error> { case idle case initialLoading
case reLoading(V) case retryLoading(E) case success(V) case failure(E) } -
࠷దͳཻબΛ w MPBEJOHͷྨ͕ࡉ͔͍ํ͕ରԠͰ͖Δέʔε͕ଟ͍ w ͕ɺྨ͕ࡉ͔͍͕ৗʹྑ͍Θ͚Ͱͳ͍ w ར༻͠ͳ͍ঢ়ଶΛ͍࣋ͬͯͯํ͕ͳ͍ w ࠷దͳMPBEJOHͷྨͷཻΛબ͢͠ w
༷ɾকདྷͷ֦ுੑɾՄಡੑɾϩδοΫཧίετFUDʜ -
$BTFϖʔδϯά QBHJOH 7 QBHJOH'BJMVSF 7 & ΛՃ enum DataState<V, E:
Error> { case idle case initialLoading case reLoading(V) case retryLoading(E) case success(V) case failure(E) } @State private var dataState: DataState<[Post], any Error> = .idle -
$BTFϖʔδϯά QBHJOH 7 QBHJOH'BJMVSF 7 & ΛՃ enum DataState<V, E:
Error> { case idle case initialLoading case reLoading(V) case retryLoading(E) case success(V) case failure(E) case paging(V) case pagingFailure(V, E) } @State private var dataState: DataState<[Post], any Error> = .idle -
$BTFϖʔδϯά QBHJOH 7 QBHJOH'BJMVSF 7 & ΛՃ enum PagingDataState<V, E:
Error> { case idle case initialLoading case reLoading(V) case retryLoading(E) case success(V) case loadingFailure(E) case paging(V) case pagingFailure(V, E) } @State private var dataState: PagingDataState<[Post], any Error> = .idle -
$BTFϖʔδϯά 7JFXͷग़͠Θ͚ var body: some View { List { switch
dataState { case .idle, .initialLoading: EmptyView() case .success(let value), .reLoading(let value): listContent(posts: value) case .failure, .retryLoading: ErrorStateView() } .overlay { if dataState.isInitialLoading { ProgressView() } } } -
$BTFϖʔδϯά 7JFXͷग़͠Θ͚ var body: some View { List { switch
dataState { case .idle, .initialLoading: EmptyView() case .success(let value), .reLoading(let value): listContent(posts: value) case .failure, .retryLoading: ErrorStateView() } .overlay { if dataState.isInitialLoading { ProgressView() } } } func listContent(posts: [Post]) -> some View { ForEach(posts) { post in Text(post.title) } } -
$BTFϖʔδϯά 7JFXͷग़͠Θ͚ var body: some View { List { switch
dataState { case .idle, .initialLoading: EmptyView() case .success(let value), .reLoading(let value): listContent(posts: value) case .failure, .retryLoading: ErrorStateView() } .overlay { if dataState.isInitialLoading { ProgressView() } } } -
$BTFϖʔδϯά 7JFXͷग़͠Θ͚ var body: some View { List { switch
dataState { case .idle, .initialLoading: EmptyView() case .success(let value), .reLoading(let value), .paging(let value), .pagingFailure(let value, _): listContent(posts: value) case .loadingFailure, .retryLoading: ErrorStateView() } .overlay { if dataState.isInitialLoading { ProgressView() } } } ϖʔδϯάதɾϖʔδϯάࣦഊ ͰલϖʔδͷσʔλΛදࣔ -
$BTFϖʔδϯά 7JFXͷग़͠Θ͚ var body: some View { List { switch
dataState { case .idle, .initialLoading: EmptyView() case .success(let value), .reLoading(let value), .paging(let value), .pagingFailure(let value, _): listContent(posts: value) case .loadingFailure, .retryLoading: ErrorStateView() } .overlay { if dataState.isInitialLoading { ProgressView() } } } -
$BTFϖʔδϯά 7JFXͷग़͠Θ͚ var body: some View { List { switch
dataState { case .idle, .initialLoading: EmptyView() case .success(let value), .reLoading(let value), .paging(let value), .pagingFailure(let value, _): listContent(posts: value) if dataState.isPagingFailure { ErrorStateView(…) } else { ProgressView() .onAppear { Task { await fetchMore() } } } case .loadingFailure, .retryLoading: ErrorStateView() -JTUԼ෦ʹ Τϥʔදࣔ ϖʔδϯάݕ -
$BTFϖʔδϯά ঢ়ଶૢ࡞ʢॳճऔಘɾϦϑϨογϡʣ func fetchInitial() async { if dataState.isLoading || dataState.isPaging
{ return } dataState.startLoading() do { dataState = .success(try await API.getPosts(minId: 0, count: 30)) } catch { dataState = .loadingFailure(error) } } -
$BTFϖʔδϯά ঢ়ଶૢ࡞ʢॳճऔಘɾϦϑϨογϡʣ func fetchInitial() async { if dataState.isLoading || dataState.isPaging
{ return } dataState.startLoading() do { dataState = .success(try await API.getPosts(minId: 0, count: 30)) } catch { dataState = .loadingFailure(error) } } extension PagingDataState { mutating func startLoading() { switch self { case .idle: self = .initialLoading case .success(let value), .pagingFailure(let value, _): self = .reLoading(value) case .loadingFailure(let error): self = .retryLoading(error) default: return } } } QBHJOH'BJMVSF͔Βϩʔυ͢Δ࣌ SF-PBEJOHʹ -
$BTFϖʔδϯά ঢ়ଶૢ࡞ʢϖʔδϯάʣ func fetchMore() async { if dataState.isLoading || dataState.isPaging
{ return } guard let users = dataState.value, let lastId = users.last?.id else { return } dataState.startPaging() do { let newUsers = try await API.getPosts(minId: lastId + 1, count: 30) dataState = .success(users + newUsers) } catch { dataState = .pagingFailure(users, error) } } -
$BTFϖʔδϯά ঢ়ଶૢ࡞ʢϖʔδϯάʣ func fetchMore() async { if dataState.isLoading || dataState.isPaging
{ return } guard let users = dataState.value, let lastId = users.last?.id else { return } dataState.startPaging() do { let newUsers = try await API.getPosts(minId: lastId + 1, count: 30) dataState = .success(users + newUsers) } catch { dataState = .pagingFailure(users, error) } } extension PagingDataState { mutating func startPaging() { switch self { case .success(let value), .pagingFailure(let value, _): self = .paging(value) default: return } } } -
$BTFϖʔδϯά ঢ়ଶૢ࡞ʢϖʔδϯάʣ func fetchMore() async { if dataState.isLoading || dataState.isPaging
{ return } guard let users = dataState.value, let lastId = users.last?.id else { return } dataState.startPaging() do { let newUsers = try await API.getPosts(minId: lastId + 1, count: 30) dataState = .success(users + newUsers) } catch { dataState = .pagingFailure(users, error) } } MPBEJOH'BJMVSFͰͳ͘ QBHJOH'BJMVSF -
$BTFϖʔδϯά ࣮ྃ var body: some View { List { switch
dataState { case .idle, .initialLoading: EmptyView() case .success(let value), .reLoading(let value), .paging(let value), .pagingFailure(let value, _): listContent(posts: value) if dataState.isPagingFailure { ErrorStateView(…) } else { ProgressView() .onAppear { Task { await fetchMore() } } } case .loadingFailure, .retryLoading: ErrorStateView() -
FOVNʹΑΔঢ়ଶཧ ϙΠϯτ w 👍ը໘ͷঢ়ଶɾඇಉظॲཧσʔλΛͭͷมͰཧͰ͖Δ w 👍ΧελϚΠζੑ͕ߴ͍ w ҙͷڍಈɾϩʔυதɾޭɾࣦഊ7JFXΛग़ͤΔ w 👎ϘΠϥʔϓϨʔτ͕ଟൃ
w ࣮ࡍͷ։ൃͰଟ͘ͷը໘Ͱ౷Ұ͞Ε͍ͯΔέʔε͕ଟ͍ -
var body: some View { PagingList( success: listContent, fetchInitial: {
try await API.getPosts(minId: 0, count: 30) }, fetchMore: { try await API.getPosts(minId: $0.id + 1, count: 30) } ) } ίϯϙʔωϯτʹΑΔঢ়ଶཧ -
var body: some View { PagingList( success: listContent, fetchInitial: {
try await API.getPosts(minId: 0, count: 30) }, fetchMore: { try await API.getPosts(minId: $0.id + 1, count: 30) } ) } ίϯϙʔωϯτʹΑΔঢ়ଶཧ ඇಉظॲཧΛ͢ ϨΠΞτΛ͢ -
FOVN ίϯϙʔωϯτʹΑΔঢ়ଶཧ 4XJUDI7JFX4UZMF w ֤ը໘ͰTXJUDIͷϘΠϥʔϓϨʔτΛॻ͘ඞཁੑ w ࣮ࡍͷ։ൃͰʢଟ͘ͷը໘Ͱʣ༷͕౷Ұ͞Ε͍ͯΔέʔε͕ଟ͍ w ঢ়ଶૢ࡞ͷϛε͕ͳ͍Θ͚Ͱͳ͍ @State
private var dataState: PagingDataState<[Post], any Error> = .idle var body: some View { PagingList(dataState: dataState, listContent: listContent) { Task { await fetchMore() } } .refreshable { await fetchInitial() } .task { await fetchInitial() } .onChange(of: dataState.isFailure) { bool in guard bool, let error = dataState.error else { return } MessageBanner.showError("Τϥʔ͕ൃੜ͠·ͨ͠", with: error.localizedDescription) } } -
FOVN ίϯϙʔωϯτʹΑΔঢ়ଶཧ 4XJUDI7JFX4UZMF w ֤ը໘ͰTXJUDIͷϘΠϥʔϓϨʔτΛॻ͘ඞཁੑ w ࣮ࡍͷ։ൃͰʢଟ͘ͷը໘Ͱʣ༷͕౷Ұ͞Ε͍ͯΔέʔε͕ଟ͍ w ঢ়ଶૢ࡞ͷϛε͕ͳ͍Θ͚Ͱͳ͍ @State
private var dataState: PagingDataState<[Post], any Error> = .idle var body: some View { PagingList(dataState: dataState, listContent: listContent) { Task { await fetchMore() } } .refreshable { await fetchInitial() } .task { await fetchInitial() } .onChange(of: dataState.isFailure) { bool in guard bool, let error = dataState.error else { return } MessageBanner.showError("Τϥʔ͕ൃੜ͠·ͨ͠", with: error.localizedDescription) } } ϖʔδϯά ϓϧϦϑ ॳճऔಘ ΤϥʔΛόφʔͰදࣔ -
'FUDI7JFX4UZMF w ֤ը໘ͰTXJUDIͷϘΠϥʔϓϨʔτΛॻ͘ඞཁੑ w ࣮ࡍͷ։ൃͰʢଟ͘ͷը໘Ͱʣ༷͕౷Ұ͞Ε͍ͯΔέʔε͕ଟ͍ w ঢ়ଶૢ࡞ͷϛε͕ͳ͍Θ͚Ͱͳ͍ @StateObject private var
viewStore: LoadingContentViewStore<Post> = .init( fetchInitial: { try await API.getPosts(minId: 0, count: 30) }, fetchMore: { try await API.getPosts(minId: $0.id + 1, count: 30) } ) var body: some View { PagingList(viewStore: viewStore, success: listContent) .task { await viewStore.loadInitial() } .onChange(of: viewStore.dataState.isFailure) { bool in guard bool, let error = viewStore.dataState.error else { return } MessageBanner.showError("Τϥʔ͕ൃੜ͠·ͨ͠", with: error.localizedDescription) } } FOVN ίϯϙʔωϯτʹΑΔঢ়ଶཧ -
'FUDI7JFX4UZMF w ֤ը໘ͰTXJUDIͷϘΠϥʔϓϨʔτΛॻ͘ඞཁੑ w ࣮ࡍͷ։ൃͰʢଟ͘ͷը໘Ͱʣ༷͕౷Ұ͞Ε͍ͯΔέʔε͕ଟ͍ w ঢ়ଶૢ࡞ͷϛε͕ͳ͍Θ͚Ͱͳ͍ @StateObject private var
viewStore: LoadingContentViewStore<Post> = .init( fetchInitial: { try await API.getPosts(minId: 0, count: 30) }, fetchMore: { try await API.getPosts(minId: $0.id + 1, count: 30) } ) var body: some View { PagingList(viewStore: viewStore, success: listContent) .task { await viewStore.loadInitial() } .onChange(of: viewStore.dataState.isFailure) { bool in guard bool, let error = viewStore.dataState.error else { return } MessageBanner.showError("Τϥʔ͕ൃੜ͠·ͨ͠", with: error.localizedDescription) } } FOVN ίϯϙʔωϯτʹΑΔঢ়ଶཧ ঢ়ଶཧΛ͢Δ4UBUF0CKFDUΛ͢ -
'FUDI7JFX4UZMF w ֤ը໘ͰTXJUDIͷϘΠϥʔϓϨʔτΛॻ͘ඞཁੑ w ࣮ࡍͷ։ൃͰʢଟ͘ͷը໘Ͱʣ༷͕౷Ұ͞Ε͍ͯΔέʔε͕ଟ͍ w ঢ়ଶૢ࡞ͷϛε͕ͳ͍Θ͚Ͱͳ͍ @StateObject private var
viewStore: LoadingContentViewStore<Post> = .init( fetchInitial: { try await API.getPosts(minId: 0, count: 30) }, fetchMore: { try await API.getPosts(minId: $0.id + 1, count: 30) } ) var body: some View { PagingList(viewStore: viewStore, success: listContent) .task { await viewStore.loadInitial() } .onChange(of: viewStore.dataState.isFailure) { bool in guard bool, let error = viewStore.dataState.error else { return } MessageBanner.showError("Τϥʔ͕ൃੜ͠·ͨ͠", with: error.localizedDescription) } } FOVN ίϯϙʔωϯτʹΑΔঢ়ଶཧ ར༻ऀଆ͔ΒൃՐՄೳ -
'FUDI7JFX4UZMF w ֤ը໘ͰTXJUDIͷϘΠϥʔϓϨʔτΛॻ͘ඞཁੑ w ࣮ࡍͷ։ൃͰʢଟ͘ͷը໘Ͱʣ༷͕౷Ұ͞Ε͍ͯΔέʔε͕ଟ͍ w ঢ়ଶૢ࡞ͷϛε͕ͳ͍Θ͚Ͱͳ͍ @StateObject private var
viewStore: LoadingContentViewStore<Post> = .init( fetchInitial: { try await API.getPosts(minId: 0, count: 30) }, fetchMore: { try await API.getPosts(minId: $0.id + 1, count: 30) } ) var body: some View { PagingList(viewStore: viewStore, success: listContent) .task { await viewStore.loadInitial() } .onChange(of: viewStore.dataState.isFailure) { bool in guard bool, let error = viewStore.dataState.error else { return } MessageBanner.showError("Τϥʔ͕ൃੜ͠·ͨ͠", with: error.localizedDescription) } } FOVN ίϯϙʔωϯτʹΑΔঢ়ଶཧ ॳճऔಘΤϥʔදࣔը໘͝ͱ ར༻ऀଆ͔ΒൃՐՄೳ -
#JOEBCMF'FUDI7JFX4UZMF @State private var dataState: PagingDataState<[Post], any Error> = .idle
var body: some View { PagingList( dataState: $dataState, success: listContent, fetchInitial: { try await API.getPosts(minId: 0, count: 30) }, fetchMore: { try await API.getPosts(minId: $0.id + 1, count: 30) } ) .onChange(of: dataState.isFailure) { isFailure in guard isFailure, let error = dataState.error else { return } MessageBanner.showError("Τϥʔ͕ൃੜ͠·ͨ͠", with: error.localizedDescription) } } FOVN ίϯϙʔωϯτʹΑΔঢ়ଶཧ -
#JOEBCMF'FUDI7JFX4UZMF @State private var dataState: PagingDataState<[Post], any Error> = .idle
var body: some View { PagingList( dataState: $dataState, success: listContent, fetchInitial: { try await API.getPosts(minId: 0, count: 30) }, fetchMore: { try await API.getPosts(minId: $0.id + 1, count: 30) } ) .onChange(of: dataState.isFailure) { isFailure in guard isFailure, let error = dataState.error else { return } MessageBanner.showError("Τϥʔ͕ൃੜ͠·ͨ͠", with: error.localizedDescription) } } FOVN ίϯϙʔωϯτʹΑΔঢ়ଶཧ #JOEJOHͰঢ়ଶ͚ͩ͢ -
#JOEBCMF'FUDI7JFX4UZMF @State private var dataState: PagingDataState<[Post], any Error> = .idle
var body: some View { PagingList( dataState: $dataState, success: listContent, fetchInitial: { try await API.getPosts(minId: 0, count: 30) }, fetchMore: { try await API.getPosts(minId: $0.id + 1, count: 30) } ) .onChange(of: dataState.isFailure) { isFailure in guard isFailure, let error = dataState.error else { return } MessageBanner.showError("Τϥʔ͕ൃੜ͠·ͨ͠", with: error.localizedDescription) } } FOVN ίϯϙʔωϯτʹΑΔঢ়ଶཧ Τϥʔදࣔը໘͝ͱ -
4JNQMF'FUDI7JFX4UZMF var body: some View { PagingList( success: listContent, fetchInitial:
{ try await API.getPosts(minId: 0, count: 30) }, fetchMore: { try await API.getPosts(minId: $0.id + 1, count: 30) } ) } FOVN ίϯϙʔωϯτʹΑΔঢ়ଶཧ -
4XJUDI 'FUDI #JOEBCMF'FUDI 4JNQMF'FUDI ঢ়ଶͷૢ࡞ ʢඇಉظॲཧʣ ར༻ऀ👨💻 ෦🤖 ར༻ऀՄೳ👨💻
෦🤖 ෦🤖 ঢ়ଶͷऔಘ Մೳ⭕ Մೳ⭕ Մೳ⭕ ෆՄೳ❌ FOVN ίϯϙʔωϯτʹΑΔঢ়ଶཧ -
FOVN ίϯϙʔωϯτʹΑΔঢ়ଶཧ ؆ܿ͞ ΧελϚΠζੑ 4XJUDI 'FUDI #JOEBCMF'FUDI 4JNQMF'FUDI ঢ়ଶͷૢ࡞
ʢඇಉظॲཧʣ ར༻ऀ👨💻 ෦🤖 ར༻ऀՄೳ👨💻 ෦🤖 ෦🤖 ঢ়ଶͷऔಘ Մೳ⭕ Մೳ⭕ Մೳ⭕ ෆՄೳ❌ -
·ͱΊ w FOVNͷදݱྗΛ্͛Ε༷ʑͳ༷ʹରԠՄೳ w ࠷దͳཻΛબ w ଟ͘ͷέʔεͰFOVNΛҾʹͱΔίϯϙʔωϯτΛར༻ w ϘΠϥʔϓϨʔτΛճආͭͭ͠ɺΧελϚΠζͰ͖Δ w
ڍಈɾσβΠϯͷ౷ҰʹޮՌత w ࠷దͳ࣮Λબ -
ࢀߟ w ϞόΠϧΞϓϦʹ͓͚ΔಡΈࠐΈॲཧपΓͷ6*ύλʔϯͱ4XJGU6*ʹΑΔ࣮ྫ w IUUQT[FOOEFWSPDLOBNFBSUJDMFTBFF f w "TZOD w
IUUQTHJUIVCDPNCBOO[BJ"TZOD w #VJMEJOHSFVTBCMFDPOUFOUMPBEJOHWJFXJO4XJGU6* w IUUQTENZUSPBOPLIJONFEJVNDPNCVJMEJOHSFVTBCMFDPOUFOUMPBEJOHWJFXXJUITXJGUVJBOEDPNCJOF GGFFC w 4XJGU6*Ͱʮάϧʔϓελϯϓʯͱ͍͏νϟοτػೳΛؒͰ࡞ͬͨ w IUUQTNFEJVNDPNLBVDIFTXJGUVJHSPVQDIBUDEF