Revision: 28789 http://sourceforge.net/p/bibdesk/svn/28789 Author: hofman Date: 2024-02-21 15:37:26 +0000 (Wed, 21 Feb 2024) Log Message: ----------- save temporary fields in fieldsarray in array to make sure they are not released by ARC when returned by fast enumeration
Modified Paths: -------------- trunk/bibdesk/BDSKFieldCollection.h trunk/bibdesk/BDSKFieldCollection.m Modified: trunk/bibdesk/BDSKFieldCollection.h =================================================================== --- trunk/bibdesk/BDSKFieldCollection.h 2024-02-21 11:01:35 UTC (rev 28788) +++ trunk/bibdesk/BDSKFieldCollection.h 2024-02-21 15:37:26 UTC (rev 28789) @@ -68,6 +68,7 @@ @interface BDSKFieldArray : NSArray { NSMutableArray *fieldNames; + NSMutableArray *fields; BDSKFieldCollection *fieldCollection; unsigned long mutations; } Modified: trunk/bibdesk/BDSKFieldCollection.m =================================================================== --- trunk/bibdesk/BDSKFieldCollection.m 2024-02-21 11:01:35 UTC (rev 28788) +++ trunk/bibdesk/BDSKFieldCollection.m 2024-02-21 15:37:26 UTC (rev 28789) @@ -118,7 +118,8 @@ if (self) { fieldCollection = collection; fieldNames = [[NSMutableArray alloc] initWithCapacity:[array count]]; - for (NSString *name in array) + fields = [[NSMutableArray alloc] initWithCapacity:[array count]]; + for (NSString *name in array) if ([fieldCollection isUsedField:name] == NO) [fieldNames addObject:name]; mutations = 0; @@ -131,14 +132,26 @@ } - (id)objectAtIndex:(NSUInteger)idx{ - return [fieldCollection fieldForName:[fieldNames objectAtIndex:idx]]; + id field = [fieldCollection fieldForName:[fieldNames objectAtIndex:idx]]; + [fields addObject:field]; + return field; } +- (NSUInteger)countByEnumeratingWithState:(NSFastEnumerationState *)state objects:(id __unsafe_unretained *)stackbuf count:(NSUInteger)len { + if (state->state == 0) { + [fields removeAllObjects]; + for (NSString *name in fieldNames) + [fields addObject:[fieldCollection fieldForName:name]]; + } + return [fields countByEnumeratingWithState:state objects:stackbuf count:len]; +} + - (id)nonEmpty{ NSUInteger i = [fieldNames count]; while (i--) if ([fieldCollection isEmptyField:[fieldNames objectAtIndex:i]]) [fieldNames removeObjectAtIndex:i]; + [fields removeAllObjects]; mutations++; return self; } This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. _______________________________________________ Bibdesk-commit mailing list Bibdesk-commit@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/bibdesk-commit