mirror of
https://github.com/gnustep/libs-base.git
synced 2025-06-02 01:21:08 +00:00
2004-01-06 Manuel Guesdon <mguesdon@orange-concept.com>
* Headers/Foundation/NSArray.h/.m: added -setValue:forKey: and -valueForKey: to comply to Mac OS X v10.3 and later documentation. git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@18322 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
ba01b14ce2
commit
11b53e1b9f
3 changed files with 75 additions and 0 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
2004-01-06 Manuel Guesdon <mguesdon@orange-concept.com>
|
||||||
|
* Headers/Foundation/NSArray.h/.m: added -setValue:forKey:
|
||||||
|
and -valueForKey: to comply to Mac OS X v10.3 and
|
||||||
|
later documentation.
|
||||||
|
|
||||||
2003-12-30 Fred Kiefer <FredKiefer@gmx.de>
|
2003-12-30 Fred Kiefer <FredKiefer@gmx.de>
|
||||||
|
|
||||||
* Headers/Foundation/NSGeometry.h
|
* Headers/Foundation/NSGeometry.h
|
||||||
|
|
|
@ -101,6 +101,7 @@
|
||||||
- (BOOL) writeToFile: (NSString*)path atomically: (BOOL)useAuxiliaryFile;
|
- (BOOL) writeToFile: (NSString*)path atomically: (BOOL)useAuxiliaryFile;
|
||||||
#ifndef STRICT_OPENSTEP
|
#ifndef STRICT_OPENSTEP
|
||||||
- (BOOL) writeToURL: (NSURL*)url atomically: (BOOL)useAuxiliaryFile;
|
- (BOOL) writeToURL: (NSURL*)url atomically: (BOOL)useAuxiliaryFile;
|
||||||
|
- (id) valueForKey: (NSString*)key;
|
||||||
#endif
|
#endif
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
@ -142,6 +143,10 @@
|
||||||
context: (void*)context;
|
context: (void*)context;
|
||||||
- (void) sortUsingSelector: (SEL)comparator;
|
- (void) sortUsingSelector: (SEL)comparator;
|
||||||
|
|
||||||
|
#ifndef STRICT_OPENSTEP
|
||||||
|
- (void) setValue: (id)value forKey: (NSString*)key;
|
||||||
|
#endif
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface NSArray (GNUstep)
|
@interface NSArray (GNUstep)
|
||||||
|
|
|
@ -43,6 +43,8 @@
|
||||||
#include "Foundation/NSMapTable.h"
|
#include "Foundation/NSMapTable.h"
|
||||||
#include "Foundation/NSLock.h"
|
#include "Foundation/NSLock.h"
|
||||||
#include "Foundation/NSDebug.h"
|
#include "Foundation/NSDebug.h"
|
||||||
|
#include "Foundation/NSValue.h"
|
||||||
|
#include "Foundation/NSNull.h"
|
||||||
#include "GNUstepBase/GSCategories.h"
|
#include "GNUstepBase/GSCategories.h"
|
||||||
#include "GSPrivate.h"
|
#include "GSPrivate.h"
|
||||||
|
|
||||||
|
@ -1130,6 +1132,53 @@ compare(id elem1, id elem2, void* context)
|
||||||
return [data writeToURL: url atomically: useAuxiliaryFile];
|
return [data writeToURL: url atomically: useAuxiliaryFile];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This overrides NSObjects implementation of this method.
|
||||||
|
* This method returns an array of objects returned by
|
||||||
|
* invoking -valueForKey: for each item in the receiver,
|
||||||
|
* substituting NSNull for nil.
|
||||||
|
* A special case: the key "count" is not forwarded to each object
|
||||||
|
* of the receiver but returns the number of objects of the receiver.<br/>
|
||||||
|
*/
|
||||||
|
- (id) valueForKey: (NSString*)key
|
||||||
|
{
|
||||||
|
id result=nil;
|
||||||
|
|
||||||
|
if ([key isEqualToString: @"count"] == YES)
|
||||||
|
{
|
||||||
|
result = [NSNumber numberWithUnsignedInt: [self count]];
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
NSMutableArray *results = nil;
|
||||||
|
NSNull* null=nil;
|
||||||
|
|
||||||
|
int i, count = [self count];
|
||||||
|
volatile id object = nil;
|
||||||
|
|
||||||
|
results = [NSMutableArray array];
|
||||||
|
|
||||||
|
for(i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
id result;
|
||||||
|
|
||||||
|
object = [self objectAtIndex: i];
|
||||||
|
result = [object valueForKey: key];
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
if (!null)
|
||||||
|
null=[NSNull null];
|
||||||
|
result = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
[results addObject: result];
|
||||||
|
}
|
||||||
|
|
||||||
|
result=results;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
|
||||||
|
|
||||||
|
@ -1723,6 +1772,22 @@ compare(id elem1, id elem2, void* context)
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Call setValue:forKey: on each of the receiver's items
|
||||||
|
* with the value and key.
|
||||||
|
*/
|
||||||
|
- (void) setValue: (id)value forKey: (NSString*)key
|
||||||
|
{
|
||||||
|
int i, count = [self count];
|
||||||
|
volatile id object = nil;
|
||||||
|
|
||||||
|
for(i = 0; i < count; i++)
|
||||||
|
{
|
||||||
|
object = [self objectAtIndex: i];
|
||||||
|
[object setValue: value
|
||||||
|
forKey: key];
|
||||||
|
}
|
||||||
|
}
|
||||||
@end
|
@end
|
||||||
|
|
||||||
@interface NSArrayEnumerator : NSEnumerator
|
@interface NSArrayEnumerator : NSEnumerator
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue