diff --git a/Medianno/MAAnno.h b/Medianno/MAAnno.h index 499809f..e7a8f13 100644 --- a/Medianno/MAAnno.h +++ b/Medianno/MAAnno.h @@ -22,6 +22,14 @@ - (NSString *)shortLocation; + (NSSet *)keyPathsForValuesAffectingShortLocation; +/* + * Tags are never manipulated through the tag objects, but always through + * tag description objects. + */ +- (NSArray *)tagDescriptions; +- (void)setTagDescriptions:(NSArray *)tagDescriptions; ++ (NSSet *)keyPathsForValuesAffectingTagDescriptions; + @end @interface MAAnno (CoreDataGeneratedAccessors) diff --git a/Medianno/MAAnno.mm b/Medianno/MAAnno.mm index 41bffbc..25a6ebb 100644 --- a/Medianno/MAAnno.mm +++ b/Medianno/MAAnno.mm @@ -8,7 +8,9 @@ #import "MAAnno.h" #import "MATag.h" +#import "MATagDescription.h" +#import @implementation MAAnno @dynamic location; @@ -49,4 +51,35 @@ return [NSSet setWithObject:@"location"]; } +- (NSArray *)tagDescriptions +{ + NSSet * tags = self.tags; + std::vector descs([tags count]); + for (MATag * tag in tags) + descs[[tag seqNo]] = [tag tag]; + + return [NSArray arrayWithObjects:&descs[0] count:descs.size()]; +} + +- (void)setTagDescriptions:(NSArray *)tagDescriptions +{ + NSManagedObjectContext *moc = [self managedObjectContext]; + + int seqNo = 0; + std::vector tags; + for (MATagDescription * tagDesc in tagDescriptions) { + MATag * tag = [NSEntityDescription insertNewObjectForEntityForName:@"MATag" inManagedObjectContext:moc]; + tag.seqNo = seqNo++; + tag.tag = tagDesc; + tag.annotation = self; + tags.push_back(tag); + } + [self setTags:[NSSet setWithObjects:&tags[0] count:tags.size()]]; +} + ++ (NSSet *)keyPathsForValuesAffectingTagDescriptions +{ + return [NSSet setWithObject:@"tags"]; +} + @end diff --git a/Medianno/MADocument.xcdatamodeld/MADocument.xcdatamodel/contents b/Medianno/MADocument.xcdatamodeld/MADocument.xcdatamodel/contents index 44e4d8d..b105729 100644 --- a/Medianno/MADocument.xcdatamodeld/MADocument.xcdatamodel/contents +++ b/Medianno/MADocument.xcdatamodeld/MADocument.xcdatamodel/contents @@ -4,7 +4,7 @@ - + @@ -17,23 +17,24 @@ - + + - - + + - - - + + + \ No newline at end of file diff --git a/Medianno/MATag.h b/Medianno/MATag.h index 9fa7c68..bc36661 100644 --- a/Medianno/MATag.h +++ b/Medianno/MATag.h @@ -13,6 +13,7 @@ @interface MATag : NSManagedObject { @private } +@property (nonatomic) int seqNo; @property (nonatomic, retain) NSManagedObject *tag; @property (nonatomic, retain) NSManagedObject *annotation; diff --git a/Medianno/MATag.mm b/Medianno/MATag.mm index 4647347..6ae9e6f 100644 --- a/Medianno/MATag.mm +++ b/Medianno/MATag.mm @@ -10,6 +10,7 @@ @implementation MATag +@dynamic seqNo; @dynamic tag; @dynamic annotation;