iphone - Programmatically create attribute - Core Data -
i have simple iphone project contains simple xcdatamodel has single entity 3 attributes..
i want know if there way programmatically add attribute entity.. i.e. if user presses "add" button of kind, simple string attribute added entity , saved..
if not possible point me in right direction..
you can programmatically alter entities can't alter managed object model after has been assigned managed object context makes useless user defined alterations. in case, wouldn't want add entities programmatically because make created persistent store file useless.
if want create more free-form , user extensible data model, have out , make entities more flexible adding optional relationship entity or entity inheritance group can model additional data.
for example: suppose have contact list , want add free form fields each contact. set entities this.
contact{ name:string phone:string userdefinedfields<-->>userdefined.contact } userdefined{ name:string contact<<-->contact.userdefinedfields }
whenever user adds new field, create new userdefined
object , add contact.userdefinedfeilds
relationship. can flesh out needed. if need more 1 type of user defined field should set this:
contact{ name:string phone:string userdefinedfields<-->>userdefined.contact } userdefined{ name:string contact<<-->contact.userdefinedfields } textfield:userdefined{ text:string } numberfield:userdefined{ numvalue:number }
you can drop in textfield or numberfield object contact.userdefinedfields
needed.
Comments
Post a Comment