Oolite 1.91.0.7646-241128-10e222e
Loading...
Searching...
No Matches
NSDictionary(OODeepCopy) Category Reference

Instance Methods

(id) - ooDeepCopyWithSharedObjects: [implementation]
 

Detailed Description

Definition at line 224 of file OODeepCopy.m.

Method Documentation

◆ ooDeepCopyWithSharedObjects:

- (id) ooDeepCopyWithSharedObjects: (NSMutableSet *) objects
implementation

Definition at line 31 of file OODeepCopy.m.

226 :(NSMutableSet *)objects
227{
228 NSUInteger i, count;
229 id *keys = NULL;
230 id *values = NULL;
231 NSDictionary *result = nil;
232 BOOL tempObjects = NO;
233
234 count = [self count];
235 if (count == 0) return [[NSDictionary dictionary] retain];
236
237 keys = malloc(sizeof *keys * count);
238 values = malloc(sizeof *values * count);
239 if (keys == NULL || values == NULL)
240 {
241 free(keys);
242 free(values);
243 [NSException raise:NSMallocException format:@"Failed to allocate space for %lu objects in %s.", (unsigned long)count, __PRETTY_FUNCTION__];
244 }
245
246 // Ensure there's an objects set even if passed nil.
247 if (objects == nil)
248 {
249 objects = [[NSMutableSet alloc] init];
250 tempObjects = YES;
251 }
252
253 @try
254 {
255 i = 0;
256 id key = nil;
257 // Deep copy members.
258 foreachkey (key, self)
259 {
260 keys[i] = [key ooDeepCopyWithSharedObjects:objects];
261 values[i] = [[self objectForKey:key] ooDeepCopyWithSharedObjects:objects];
262 i++;
263 }
264
265 // Make NSDictionary of results.
266 result = [[NSDictionary alloc] initWithObjects:values forKeys:keys count:count];
267 }
268 @finally
269 {
270 // Release objects.
271 for (i = 0; i < count; i++)
272 {
273 [keys[i] release];
274 [values[i] release];
275 }
276
277 free(keys);
278 free(values);
279 if (tempObjects) [objects release];
280 }
281
282 // Collections are not reused because comparing them is arbitrarily slow.
283 return result;
284}
#define foreachkey(VAR, DICT)
Definition OOCocoa.h:366
unsigned count
return nil

The documentation for this category was generated from the following file: