NSRelationshipDescription.m
1 /* Copyright (c) 2008 Dan Knapp 2 3 Permission is hereby granted, free of charge, to any person obtaining a copy of 4 this software and associated documentation files (the "Software"), to deal in 5 the Software without restriction, including without limitation the rights to 6 use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of 7 the Software, and to permit persons to whom the Software is furnished to do so, 8 subject to the following conditions: 9 10 The above copyright notice and this permission notice shall be included in all 11 copies or substantial portions of the Software. 12 13 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS 15 FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR 16 COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER 17 IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 18 CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ 19 #import <CoreData/NSEntityDescription.h> 20 #import <CoreData/NSRelationshipDescription.h> 21 #import <Foundation/NSKeyedUnarchiver.h> 22 23 @implementation NSRelationshipDescription 24 25 - initWithCoder: (NSCoder *) coder { 26 if (![coder allowsKeyedCoding]) 27 [NSException raise: NSInvalidArgumentException 28 format: @"%@ can not initWithCoder:%@", [self class], 29 [coder class]]; 30 31 [super initWithCoder: coder]; 32 33 _deleteRule = [coder decodeIntForKey: @"NSDeleteRule"]; 34 _destinationEntity = [coder decodeObjectForKey: @"NSDestinationEntity"]; 35 _inverseRelationship = [coder decodeObjectForKey: @"NSInverseRelationship"]; 36 _optional = [coder decodeBoolForKey: @"NSIsOptional"]; 37 _maxCount = [coder decodeIntForKey: @"NSMaxCount"]; 38 _minCount = [coder decodeIntForKey: @"NSMinCount"]; 39 40 _destinationEntityName = 41 [coder decodeObjectForKey: @"_NSDestinationEntityName"]; 42 _inverseRelationshipName = 43 [coder decodeObjectForKey: @"_NSInverseRelationshipName"]; 44 45 return self; 46 } 47 48 - (NSString *) description { 49 return [NSString stringWithFormat: @"<NSRelationshipDescription: %@->%@>", 50 _propertyName, _destinationEntityName]; 51 } 52 53 - (BOOL) isToMany { 54 return (_minCount == 1 && _maxCount == 1) ? NO : YES; 55 } 56 57 - (int) maxCount { 58 return _maxCount; 59 } 60 61 - (int) minCount { 62 return _minCount; 63 } 64 65 - (NSDeleteRule) deleteRule { 66 return _deleteRule; 67 } 68 69 - (NSEntityDescription *) destinationEntity { 70 return _destinationEntity; 71 } 72 73 - (NSRelationshipDescription *) inverseRelationship { 74 return _inverseRelationship; 75 } 76 77 - (void) setMaxCount: (int) value { 78 if ([_entity _hasBeenInstantiated]) { 79 NSLog(@"Attempt to modify entity after instantiating it."); 80 return; 81 } 82 83 _maxCount = value; 84 } 85 86 - (void) setMinCount: (int) value { 87 if ([_entity _hasBeenInstantiated]) { 88 NSLog(@"Attempt to modify entity after instantiating it."); 89 return; 90 } 91 92 _minCount = value; 93 } 94 95 - (void) setDeleteRule: (NSDeleteRule) value { 96 if ([_entity _hasBeenInstantiated]) { 97 NSLog(@"Attempt to modify entity after instantiating it."); 98 return; 99 } 100 101 _deleteRule = value; 102 } 103 104 - (void) setDestinationEntity: (NSEntityDescription *) value { 105 if ([_entity _hasBeenInstantiated]) { 106 NSLog(@"Attempt to modify entity after instantiating it."); 107 return; 108 } 109 110 _destinationEntity = value; 111 _destinationEntityName = [value name]; 112 } 113 114 - (void) setInverseRelationship: (NSRelationshipDescription *) value { 115 if ([_entity _hasBeenInstantiated]) { 116 NSLog(@"Attempt to modify entity after instantiating it."); 117 return; 118 } 119 120 _inverseRelationship = value; 121 _inverseRelationshipName = [value name]; 122 } 123 124 @end