Hi
I’ve never used Cored Data but slowing getting an idea of how to model things which isn’t just using an SQL approach. With help I have these rough ideas. I want to be able to track in my app, players, teams and games and some minor stats. The stats seems to be where the problem is. But I’ll get to that
class Player: NSManagedObject {
@NSManaged var name: String
@NSManaged var team: Team?
}
class Team: NSManagedObject {
@NSManaged var name: String
@NSManaged var players: Set<Player>
@NSManaged var games: Set<Game>
}
class Game: NSManagedObject {
@NSManaged var teams: Set<Team>
@NSManaged var date: NSDate
@NSManaged var played: Set<Player>
}
So I have my players and they obviously belong to a team. Because over time players could change teams or they might not actually play in a game I have added a Set of <Player>
to the Game object so I can see who played in any given time and go back over seasons. I think that’s an ok approach?
My next thing is I wanted to be able to track some minor stats, so say I wanted to know how long someone had played. I thought I could then add a dictionary with the player name
and minutes played
. Using a dictionary isn’t possible in Core Data it seems. So for my use case, what is the best practice in this situation, whether it be Core Data or SQL or something else?
I am proficient in SQL so that’s why most of my data solutions come from that style of thinking. I don’t know much at all about data storage in iOS so not sure of the best approach.