gpt4 book ai didi

core-data - 将 SwiftUI 与核心数据一起使用

转载 作者:行者123 更新时间:2023-12-04 04:14:31 24 4
gpt4 key购买 nike

SwiftUI 表需要绑定(bind)到将整个模型对象存储在内存中的数组。对于小型数据集,便利性与性能的权衡是有意义的。但是对于具有数万/数十万个值的数据集,通过查询数据源来呈现表的老式方法似乎仍然是可行的方法。 (考虑一个简单的字典/词库应用程序。)。

有没有办法在 SwiftUI 中实现 dataSource 样式/CoreData 支持的表?

最佳答案

列表不需要 Array . Data必须符合 RandomAccessCollection 协议(protocol)。
这也可能是您的NSFetchedResultsController .

extension List {
/// Creates a List that computes its rows on demand from an underlying
/// collection of identified data.
@available(watchOS, unavailable)
public init<Data, RowContent>(
_: Data,
selection _: Binding<Selection>?,
rowContent _: @escaping (Data.Element.IdentifiedValue) -> RowContent
) where Content == ForEach<Data, HStack<RowContent>>,
Data: RandomAccessCollection,
RowContent: View,
Data.Element:
Identifiable

/// Creates a List that computes its rows on demand from an underlying
/// collection of identified data.
@available(watchOS, unavailable)
public init<Data, RowContent>(
_: Data,
selection _: Binding<Selection>?,
action _: @escaping (Data.Element.IdentifiedValue) -> Void,
rowContent _: @escaping (Data.Element.IdentifiedValue) -> RowContent
) where Content == ForEach<Data, Button<HStack<RowContent>>>,
Data: RandomAccessCollection,
RowContent: View, Dat
}

关于core-data - 将 SwiftUI 与核心数据一起使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56590381/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com