UA-17470720-3

Jump to content


Photo
- - - - -

DataDefinitionFactory.. might come in handy one day

data-definitions

  • Please log in to reply
2 replies to this topic

#1 ozie

ozie

    ¯\_(ツ)_/¯

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 526 posts
  • LocationAustralia
Reputation: 169
Popular

Posted 01 May 2013 - 09:07 PM

So the story goes that i was stuck.. I had two entity objects that were linked and both had their own view controllers to display lists of each item and add/edit each entity object

So the Person entity list view had custom cells because it had email buttons and phone buttons
But the other Building Object only had to link "Person"s objects to it.. it didnt need to have the same list view extra as the list view for Person within the Building view, as it was a selection list using SCObjectSelectionAttributes

So the selection view just needed to list Person by name to select. The view also has the edit button in the navbar to add new Persons

But the problem was if Person ever changed in the database, i would have to maintain two classes that both used the Person object for adding new Persons

This is where DataDefinitionFactory fixes this tiny issue

you create a definition of the Person object and can use it in both views using one line of code.. and the DataDefinitionFactory class is where you maintain the code of the Person Definition Entity

@interface DataDefinitionFactory : NSObject
+ (SCEntityDefinition *)createPersonDefinition;
@end
@implementation DataDefinitionFactory
+ (SCEntityDefinition *)createPersonDefinition
{
SCEntityDefinition *personDef = [SCEntityDefinition definitionWithEntityName:@"Person" ...];
...
...
}

Now in both your view controllers, you should do something like when you need the definition:

SCEntityDefinition *personDef = [DataDefinitionFactory createPersonDefinition];



Big thanks to Tarek for this little gem:)

Edited by ozie, 01 May 2013 - 09:11 PM.

  • Tarek and wizgod like this

P.S. I hate Swift.. don't talk Swift.. Too old school to learn yet another programming language.


#2 Everett

Everett

    Ev

  • STV 5.0 Pro
  • PipPipPipPipPip
  • 191 posts
  • LocationMichigan
Reputation: 60
Outstanding

Posted 29 May 2013 - 07:30 AM

Hi Oz, dumb question.  Where does DataDefinitionFactory come from?  I couldn't find it in any of the SC headers or Core Data headers.  Is it a 3rd party library?



#3 ozie

ozie

    ¯\_(ツ)_/¯

  • STV 5.0 Pro
  • PipPipPipPipPipPipPip
  • 526 posts
  • LocationAustralia
Reputation: 169
Popular

Posted 29 May 2013 - 03:30 PM

Everett.. it could be called anything.. its just the class name, and since its full of different datadefinitions, its just a factory full :)


P.S. I hate Swift.. don't talk Swift.. Too old school to learn yet another programming language.






Also tagged with one or more of these keywords: data-definitions

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users