ios - Learning Core Data. Entities, Adding and Loading -
so, i'm trying use core data save instances of "screenshot" class, consist of:
nsstring *note; nsdata *screenshot; nsdata *thumbnailofscreenshot; nstimeinterval date;
in core data file, have 2 entities because want fetch large images when necessary, , 1 @ time (it used in uitableview).
entity 1 called screenshot , consists of 4 attributes above, whereas *screenshot transient. entity has 1 relationship entity 2(an int called index).
entity 2 has 1 attribute binary data field large images. 1 relationship entity 1.
so, first question: remotely close being correct? i'm little unsure if need transient attribute "screenshot", in entity 1. and confused if need create new class entity 2, seems abit odd, since contain images.
for now, i'm trying add , load instances , db. here how (think) add instance db, not sure puts in db right away?:
screenshot *s = [nsentitydescription insertnewobjectforentityforname:@"screenshot" inmanagedobjectcontext:context];
i in on head, appreciated. have read several guides, none targeting similar this.
transient properties not saved core data (they neither retrieved nor saved out backing store). useful calculating sort of property based on stored properties (e.g. use them queries based on first letter of person's last name -- i'm storing full last name, firstletteroflastname transient property -- 1 can order results on since core data knows it).
if i'm understanding model correctly, want no transient properties @ all.
i don't think need entirely new model "large images". can instruct core data optimize it's backing store large binary attributes turning on "store in external record file". you'll find in data model inspector pane underneath transient , optional set. keep actual backing db snappy, allow core data retrieve these large binary attributes , may still work them seemlessly core data nsmanagedobject instance.
also, in general, not relate items "index" value of other stored core data object. there's plenty of reasons so, in general, core data relationships for. if "movie" has multiple "screenshots", e.g, have relationship on movie instance called "screenshots" add each screenshot (it's nsmutableset far care).
core data object graph, not relational database. if add same object instance 2 relationships on different owner-object instances, aren't duplicating child-object -- core data work interrelate them (assuming models setup in way).
Comments
Post a Comment