我如何模拟iOS中测试的pectractedFetchedResults?

发布于 2025-02-13 08:02:50 字数 1066 浏览 1 评论 0原文

我正在努力工作如何使用协议来表示核心数据类型,sectionFetchedResults使我能够为我的ios swiftui应用添加快照测试。

以下是代码,我尝试使用协议来表示player squeadview 表示代表。

您认为我可以做什么?

import SwiftUI

struct SquadContainerView: View {
    @Environment(\.managedObjectContext) var viewContext
    @SectionedFetchRequest var players: SectionedFetchResults<Int16, Player>
    private let team: Teamable
    
    init(team: Teamable) {
        let predicate =  NSPredicate(format: "%K == %@", #keyPath(Player.team.id), team.id as CVarArg)
        _players = SectionedFetchRequest<Int16, Player>(sectionIdentifier: \.position, sortDescriptors: [SortDescriptor(\.shirtNumber)], predicate: predicate)
        self.team = team
    }
    
    var body: some View {
        SquadView(viewModel: .init(team: team,
                                   playerService: PlayerService(viewContext),
                                   teamService: TeamService(viewContext)),
                  players: players)
    }
}

I am struggling to work how I can use a protocol to represent the core data type, SectionFetchedResults to enable me to add snapshot testing for my iOS SwiftUI app.

Below is the code and I am trying to pass players into SquadView using a protocol to represent it.

What do you think I could do?

import SwiftUI

struct SquadContainerView: View {
    @Environment(\.managedObjectContext) var viewContext
    @SectionedFetchRequest var players: SectionedFetchResults<Int16, Player>
    private let team: Teamable
    
    init(team: Teamable) {
        let predicate =  NSPredicate(format: "%K == %@", #keyPath(Player.team.id), team.id as CVarArg)
        _players = SectionedFetchRequest<Int16, Player>(sectionIdentifier: \.position, sortDescriptors: [SortDescriptor(\.shirtNumber)], predicate: predicate)
        self.team = team
    }
    
    var body: some View {
        SquadView(viewModel: .init(team: team,
                                   playerService: PlayerService(viewContext),
                                   teamService: TeamService(viewContext)),
                  players: players)
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文