25 #import "CoreDataHeaders.h"
27 @implementation NSAttributeDescription
29 - (NSAttributeType) attributeType
31 return _attributeType;
34 - (void) setAttributeType: (NSAttributeType) type
36 [
self _ensureEditableWithReason: @"Tried to set the type of an attribute "
38 _attributeType = type;
41 - (NSString *) attributeValueClassName
43 switch(_attributeType)
45 case NSUndefinedAttributeType:
return @"NSNull";
46 case NSInteger16AttributeType:
return @"NSNumber";
47 case NSInteger32AttributeType:
return @"NSNumber";
48 case NSInteger64AttributeType:
return @"NSNumber";
49 case NSDecimalAttributeType:
return @"NSDecimalNumber";
50 case NSDoubleAttributeType:
return @"NSNumber";
51 case NSFloatAttributeType:
return @"NSNumber";
52 case NSStringAttributeType:
return @"NSString";
53 case NSBooleanAttributeType:
return @"NSNumber";
54 case NSDateAttributeType:
return @"NSDate";
55 case NSBinaryDataAttributeType:
return @"NSData";
65 - (void) setDefaultValue: (
id) aValue
67 [
self _ensureEditableWithReason: @"Tried to set the default value for "
68 @"an attribute already in use."];
70 ASSIGN(_defaultValue, aValue);
75 - (id) initWithCoder: (NSCoder *) coder
77 if ((
self = [super initWithCoder: coder]))
79 if ([coder allowsKeyedCoding])
81 _attributeType = [coder decodeIntForKey: @"AttributeType"];
84 ASSIGN(_defaultValue, [coder decodeObjectForKey:
@"DefaultValue"]);
88 [coder decodeValueOfObjCType: @encode(int) at: &_attributeType];
90 ASSIGN(_defaultValue, [coder decodeObject]);
97 - (void) encodeWithCoder: (NSCoder *) coder
99 [
super encodeWithCoder: coder];
101 if ([coder allowsKeyedCoding])
103 [coder encodeInt: _attributeType forKey: @"AttributeType"];
106 [coder encodeObject: _defaultValue forKey: @"DefaultValue"];
110 [coder encodeValueOfObjCType: @encode(int) at: &_attributeType];
112 [coder encodeObject: _defaultValue];
118 - (id) copyWithZone: (NSZone *) zone
120 NSAttributeDescription * attr = [
super copyWithZone: zone];
122 [attr setAttributeType: _attributeType];
124 [attr setDefaultValue: _defaultValue];