More KVC fixes

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@12810 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-Macdonald 2002-02-27 09:25:30 +00:00
parent 22f8f72d56
commit 47fb20dd9b
3 changed files with 47 additions and 1 deletions

View file

@ -4,6 +4,7 @@
* Source/GSValue.m: attempt to correct encoding. * Source/GSValue.m: attempt to correct encoding.
* Source/NSKeyValueCoding.m: Fix termination of method names with nuls * Source/NSKeyValueCoding.m: Fix termination of method names with nuls
from report by Manuel Guesdon. from report by Manuel Guesdon.
* Source/NSDictionary.m: Implement MacOS-X compatible KVC behavior.
2002-02-26 Richard Frith-Macdonald <rfm@gnu.org> 2002-02-26 Richard Frith-Macdonald <rfm@gnu.org>

View file

@ -67,6 +67,7 @@
- (BOOL) writeToFile: (NSString*)path atomically: (BOOL)useAuxiliaryFile; - (BOOL) writeToFile: (NSString*)path atomically: (BOOL)useAuxiliaryFile;
#ifndef STRICT_OPENSTEP #ifndef STRICT_OPENSTEP
- (id) valueForKey: (NSString*)key;
- (BOOL) writeToURL: (NSURL*)url atomically: (BOOL)useAuxiliaryFile; - (BOOL) writeToURL: (NSURL*)url atomically: (BOOL)useAuxiliaryFile;
#endif #endif
@end @end
@ -82,7 +83,10 @@
- (void) removeObjectsForKeys: (NSArray*)keyArray; - (void) removeObjectsForKeys: (NSArray*)keyArray;
- (void) setObject: (id)anObject forKey: (id)aKey; // Primitive - (void) setObject: (id)anObject forKey: (id)aKey; // Primitive
- (void) setDictionary: (NSDictionary*)otherDictionary; - (void) setDictionary: (NSDictionary*)otherDictionary;
#ifndef STRICT_OPENSTEP
- (void) takeStoredValue: (id)value forKey: (NSString*)key;
- (void) takeValue: (id)value forKey: (NSString*)key;
#endif
@end @end
#ifndef NO_GNUSTEP #ifndef NO_GNUSTEP

View file

@ -936,6 +936,14 @@ static NSString *indentStrings[] = {
} }
} }
/**
* Default implementation for this class is to return the value stored in
* the dictionary under the specified key, or nil if there is no value.
*/
- (id) valueForKey: (NSString*)key
{
return [self objectForKey: key];
}
@end @end
@implementation NSMutableDictionary @implementation NSMutableDictionary
@ -1096,4 +1104,37 @@ static NSString *indentStrings[] = {
[self addEntriesFromDictionary: otherDictionary]; [self addEntriesFromDictionary: otherDictionary];
} }
/**
* Default implementation for this class is equivalent to the
* -setObject:forKey: method unless value is nil, in which case
* it is equivalent to -removeObjectForKey:
*/
- (void) takeStoredValue: (id)value forKey: (NSString*)key
{
if (value == nil)
{
[self removeObjectForKey: key];
}
else
{
[self setObject: value forKey: key];
}
}
/**
* Default implementation for this class is equivalent to the
* -setObject:forKey: method unless value is nil, in which case
* it is equivalent to -removeObjectForKey:
*/
- (void) takeValue: (id)value forKey: (NSString*)key
{
if (value == nil)
{
[self removeObjectForKey: key];
}
else
{
[self setObject: value forKey: key];
}
}
@end @end