I'm trying to work with Core Data & SwiftUI's previews and think I'm close but haven't been able to get this to work.
static var previews: some View {
let context = (UIApplication.shared.delegate as! AppDelegate).persistentContainer.viewContext
let newGame = Game.init(context: context)
newGame.gameName = "Testy Game"
newGame.gameDescription = "Wooo play the thing"
newGame.goal = Goal.init(goalName: "Try Harder", goalComplete: false, goalOfGame: newGame)
return GameGoalsDetail(game: newGame).environment(\.managedObjectContext, context)
}
}
I'm getting a "Ambiguous reference to member 'init(entity:insertInto:)'" on the newGame.Goal = Goal.init... line.
I'm trying to figure out how to initialize a new Game and then initialize a connected Goal to it right after.
My Core Data Game class takes gameName, gameDescription, and a goal as a NSSet?. The Core Data Goal class has goalName, goalComplete, & goalOfGame: Game?. I think my issue is in connecting the two.
Appreciate the help in advance and willing to share more code if requested.
@NSManagedObjecthave definedinitwith context. In with context willGoalbe inserted? By the way, you don't have to use.init(). Just callGame(context: context)