diff options
-rw-r--r-- | Source/SPArrayAdditions.h | 10 | ||||
-rw-r--r-- | Source/SPArrayAdditions.m | 7 | ||||
-rw-r--r-- | Source/SPExportFilenameUtilities.m | 4 |
3 files changed, 20 insertions, 1 deletions
diff --git a/Source/SPArrayAdditions.h b/Source/SPArrayAdditions.h index 565e0393..cf3673d5 100644 --- a/Source/SPArrayAdditions.h +++ b/Source/SPArrayAdditions.h @@ -86,4 +86,14 @@ static inline void NSMutableArrayReplaceObject(NSArray *self, CFIndex idx, id an - (NSArray *)subarrayWithIndexes:(NSIndexSet *)indexes; +/** + * Variant of objectAtIndex: that avoids the "index out of bounds" exception by + * just returning nil instead. + * + * @warning This method is NOT thread-safe. + * @param index An index + * @return The object located at index or nil. + */ +- (id)objectOrNilAtIndex:(NSUInteger)index; + @end diff --git a/Source/SPArrayAdditions.m b/Source/SPArrayAdditions.m index 91af56e4..0fe75483 100644 --- a/Source/SPArrayAdditions.m +++ b/Source/SPArrayAdditions.m @@ -145,4 +145,11 @@ return subArray; } +- (id)objectOrNilAtIndex:(NSUInteger)index +{ + if([self count] <= index) + return nil; + return [self objectAtIndex:index]; +} + @end diff --git a/Source/SPExportFilenameUtilities.m b/Source/SPExportFilenameUtilities.m index d9637e4d..71422b28 100644 --- a/Source/SPExportFilenameUtilities.m +++ b/Source/SPExportFilenameUtilities.m @@ -47,7 +47,8 @@ // Get the current export file extension NSString *extension = [self currentDefaultExportFileExtension]; - filename = [self expandCustomFilenameFormatUsingTableName:[[tablesListInstance tables] objectAtIndex:1]]; + //note that there will be no tableName if the export is done from a query result without a database selected (or empty). + filename = [self expandCustomFilenameFormatUsingTableName:[[tablesListInstance tables] objectOrNilAtIndex:1]]; if (![[filename pathExtension] length] && [extension length] > 0) filename = [filename stringByAppendingPathExtension:extension]; } @@ -319,6 +320,7 @@ * Uses the current custom filename field as a data source. * * @param table A table name to be used within the expanded filename. + * Can be nil. * * @return The expanded filename. */ |