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)
}
}