English 中文(简体)
Help setting up a data model in Core Data
原标题:

I am new to Core Data, and have been trying to figure out how to set up my data model. I made a sample table to try and show how I need the data to relate.

First Name Last Name Competitor Number Gender Team Competition Game Name     All Time high Competition Scores 
Jon         Doe            1          M  Gamers     January   Donkey Kong       Lvl 5         Level #         1 2 3 4
                                                                                       Trys to complete    1   0 1 3
                                                             Pac Man        8000               game 1   7000      
                                                                                              game 2   8500      
                                                                                              game 3   9000      
                                                       March  Donkey Kong         Lvl 5        Level #        
                                                                                             trys        
                                                             Pac Man                         Game 1        
                                                                                              Game 2        
                                                                                              Game 3        
     Bob        Smith       2              M Players   January    Asteroids        34000            Game 1    30000      
                                                                                              Game 2   20000      
                                                                                              Game 3   10000      
                                                              Pac Man          7000           Game 1       5000      
                                                                                              Game 2    4500      
                                                                                              Game 3    7000  

From what I have read I think I need entities for Players, Competitions, GameNames. With To-Many relationships between players and competitions and gameNames, also a relationship between gameNames and competitions.

And then attributes of First Name, Last Name, competitor number, gender, team for players. Attributes for competition would be month (or name), Attributes for GameName would be name.

And then I get stuck I don t know if the all time high should be an attribute of GameName because it needs to be associated with the individual player, and players will have different high scores for different games. I need to be able to keep track of number of tries and the highest level for games like donkey kong, so would I make attributes of game1, game2, game3? But other games like pac-man I only care about the end score. So would game1, game2, game3 be attributes of the player or the game? or should it be an entire entity by itself?

thanks for any help.

问题回答

As for your specific question:

so would I make attributes of game1, game2, game3? But other games like pac-man I only care about the end score. So would game1, game2, game3 be attributes of the player or the game? or should it be an entire entity by itself?

I would suggest you create an object class called Games and give it the attributes you need, such as highscore, highest level, etc.

If you have different types of Games you have two choices:

  1. you create a hierarchy of Games where the root Game-Class contains all the common attributes and the descendants include their specifics - or what I prefer in those cases,

  2. where the variations between the types are not too complicated and too many, I just put the attributes in one class and use them for the type where they are required.

So in your case you first need to write down in a structured way which attributes you need for which Games and then decide either between classes and subclasses vs attribute overload and redundancy.

ps this is actually not so much a core data issue but a DB-design.

You ll see, once you are done with this structuring everything becomes much clearer...





相关问题
Code sign Error

I have created a new iPhone application.I have two mach machines. I have created the certificate for running application in iPhone in one mac. Can I use the other mac for running the application in ...

ABPersonViewController Usage for displaying contact

Created a View based Project and added a contact to the AddressBook using ABAddressBookRef,ABRecordRef now i wanted to display the added contact ABPersonViewController is the method but how to use in ...

将音频Clips从Peter改为服务器

我不禁要问,那里是否有任何实例表明从Peit向服务器发送音响。 I m不关心电话或SIP风格的解决办法,只是一个简单的袖珍流程......

• 如何将搜查线重新定位?

我正试图把图像放在搜索条左边。 但是,问题始于这里,搜索条线不能重新布署。

热门标签