How to model this scenario

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.

I would definitely go with the CoreData approach. You can eventually move it to the cloud with great ease as well which is a big plus. It might be weird because of data in CoreData is structured and how it is referred to, which might be confusing coming from SQL. Have you looked at the CoreData Series book?

Hi @marciokoko

Yeah I think i’m going to do that. I want to learn Core Data so this works for me. I’m not sure how though to save this portion of my data as a dictionary isn’t available. What’s the best way to be modelling how many minutes a player has played in a particular game in CoreData?