vendor/Pods/NanoStore/Classes/Advanced/NSFNanoResult.m in nano-store-0.6.2 vs vendor/Pods/NanoStore/Classes/Advanced/NSFNanoResult.m in nano-store-0.6.3

- old
+ new

@@ -25,21 +25,22 @@ */ #import "NSFNanoResult.h" #import "NanoStore_Private.h" -@implementation NSFNanoResult -{ -@protected - /** \cond */ - NSDictionary *results; - /** \endcond */ -} +@interface NSFNanoResult () -@synthesize numberOfRows; -@synthesize error; +/** \cond */ +@property (nonatomic, assign, readwrite) NSUInteger numberOfRows; +@property (nonatomic, strong, readwrite) NSError *error; +@property (nonatomic) NSDictionary *results; +/** \endcond */ +@end + +@implementation NSFNanoResult + /** \cond */ - (id)init { if ((self = [super init])) { @@ -55,28 +56,28 @@ } /** \endcond */ - (NSString *)description { - NSUInteger numberOfColumns = [[results allKeys]count]; + NSUInteger numberOfColumns = [[_results allKeys]count]; NSMutableString *description = [NSMutableString string]; [description appendString:@"\n"]; [description appendString:[NSString stringWithFormat:@"Result address : %p\n", self]]; [description appendString:[NSString stringWithFormat:@"Number of columns : %ld\n", numberOfColumns]]; - if (nil == error) + if (nil == _error) if ([[self columns]count] > 0) [description appendString:[NSString stringWithFormat:@"Columns : %@\n", [[self columns]componentsJoinedByString:@", "]]]; else [description appendString:[NSString stringWithFormat:@"Columns : %@\n", @"()"]]; else [description appendString:[NSString stringWithFormat:@"Columns : %@\n", @"<column info not available>"]]; - [description appendString:[NSString stringWithFormat:@"Number of rows : %ld\n", numberOfRows]]; - if (nil == error) + [description appendString:[NSString stringWithFormat:@"Number of rows : %ld\n", _numberOfRows]]; + if (nil == _error) [description appendString:[NSString stringWithFormat:@"Error : %@\n", @"<no error>"]]; else - [description appendString:[NSString stringWithFormat:@"Error : %@\n", [error localizedDescription]]]; + [description appendString:[NSString stringWithFormat:@"Error : %@\n", [_error localizedDescription]]]; // Print up to the first ten rows to help visualize the cursor if (0 != numberOfColumns) { [description appendString:@"Preview of contents:\n "]; NSUInteger i; @@ -103,15 +104,15 @@ [description appendString:[NSString stringWithFormat:@"%-15s\n ", value]]; } } // Print the preview of the contents - if (numberOfRows > 0) { - NSInteger numberOfRowsToPrint = numberOfRows; + if (_numberOfRows > 0) { + NSInteger numberOfRowsToPrint = _numberOfRows; NSUInteger j; - if (numberOfRows > 100) { + if (_numberOfRows > 100) { numberOfRowsToPrint = 100; } for (i = 0; i < numberOfRowsToPrint; i++) { [description appendString:[NSString stringWithFormat:@"%-15ld | ", i]]; @@ -139,30 +140,30 @@ return description; } - (NSFOrderedDictionary *)dictionaryDescription { - NSUInteger numberOfColumns = [[results allKeys]count]; + NSUInteger numberOfColumns = [[_results allKeys]count]; NSFOrderedDictionary *values = [NSFOrderedDictionary new]; values[@"Result address"] = [NSString stringWithFormat:@"%p", self]; values[@"Number of columns"] = @(numberOfColumns); - if (nil == error) { + if (nil == _error) { if ([[self columns]count] > 0) { values[@"Columns"] = [[self columns]componentsJoinedByString:@", "]; } else { values[@"Columns"] = @"()"; } } else { values[@"Columns"] = @"<column info not available>"; } - values[@"Number of rows"] = @(numberOfRows); - if (nil == error) { + values[@"Number of rows"] = @(_numberOfRows); + if (nil == _error) { values[@"Error"] = @"<nil>"; } else { - values[@"Error"] = [NSString stringWithFormat:@"%@", [error localizedDescription]]; + values[@"Error"] = [NSString stringWithFormat:@"%@", [_error localizedDescription]]; } // Print up to the first ten rows to help visualize the cursor if (0 != numberOfColumns) { NSUInteger i; @@ -194,15 +195,15 @@ } } [printedContent addObject:[contentString copy]]; // Print the preview of the contents - if (numberOfRows > 0) { - NSInteger numberOfRowsToPrint = numberOfRows; + if (_numberOfRows > 0) { + NSInteger numberOfRowsToPrint = _numberOfRows; NSUInteger j; - if (numberOfRows > 100) { + if (_numberOfRows > 100) { numberOfRowsToPrint = 100; } [contentString setString:@""]; @@ -249,46 +250,41 @@ #pragma mark - - (NSArray *)columns { - return [results allKeys]; + return [_results allKeys]; } - (NSString *)valueAtIndex:(NSUInteger)index forColumn:(NSString *)column { - return [[results objectForKey:column]objectAtIndex:index]; + return [[_results objectForKey:column]objectAtIndex:index]; } - (NSArray *)valuesForColumn:(NSString *)column { - NSArray *values = [results objectForKey:column]; + NSArray *values = [_results objectForKey:column]; if (nil == values) values = [NSArray array]; return values; } - (NSString *)firstValue { - NSArray *columns = [results allKeys]; - if (([columns count] > 0) && (numberOfRows > 0)) { - return [[results objectForKey:[columns objectAtIndex:0]]objectAtIndex:0]; + NSArray *columns = [_results allKeys]; + if (([columns count] > 0) && (_numberOfRows > 0)) { + return [[_results objectForKey:[columns objectAtIndex:0]]objectAtIndex:0]; } return nil; } -- (NSError *)error -{ - return [error copy]; -} - - (void)writeToFile:(NSString *)path; { - [results writeToFile:[path stringByExpandingTildeInPath] atomically:YES]; + [_results writeToFile:[path stringByExpandingTildeInPath] atomically:YES]; } #pragma mark - Private Methods #pragma mark - @@ -314,11 +310,11 @@ [[NSException exceptionWithName:NSFUnexpectedParameterException reason:[NSString stringWithFormat:@"*** -[%@ %@]: theResults is not of type NSDictionary.", [self class], NSStringFromSelector(_cmd)] userInfo:nil]raise]; if ((self = [self init])) { - results = theResults; + _results = theResults; [self _calculateNumberOfRows]; } return self; } @@ -334,39 +330,32 @@ [[NSException exceptionWithName:NSFUnexpectedParameterException reason:[NSString stringWithFormat:@"*** -[%@ %@]: theError is not of type NSError.", [self class], NSStringFromSelector(_cmd)] userInfo:nil]raise]; if ((self = [self init])) { - error = theError; + _error = theError; [self _calculateNumberOfRows]; } return self; } -- (void)_setError:(NSError *)theError -{ - if (error != theError) { - error = theError; - } -} - - (void)_reset { - numberOfRows = -1; - results = nil; - error = nil; + _numberOfRows = -1; + _results = nil; + _error = nil; } - (void)_calculateNumberOfRows { // We cache the value once, for performance reasons - if (-1 == numberOfRows) { - NSArray *allKeys = [results allKeys]; + if (-1 == _numberOfRows) { + NSArray *allKeys = [_results allKeys]; if ([allKeys count] == 0) - numberOfRows = 0; + _numberOfRows = 0; else - numberOfRows = [[results objectForKey:[allKeys lastObject]]count]; + _numberOfRows = [[_results objectForKey:[allKeys lastObject]]count]; } } /** \endcond */ @end \ No newline at end of file