Skip to content

Commit 015f937

Browse files
committed
Using own queue, initialized errors, prefixed map method
1 parent b516d5e commit 015f937

File tree

3 files changed

+9
-7
lines changed

3 files changed

+9
-7
lines changed

NSArray+Map.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,6 @@
88

99
@interface NSArray (Map)
1010

11-
- (NSArray *)mapObjectsUsingBlock:(id (^)(id obj, NSUInteger idx))block;
11+
- (NSArray *)rnfs_mapObjectsUsingBlock:(id (^)(id obj, NSUInteger idx))block;
1212

1313
@end

NSArray+Map.m

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66

77
@implementation NSArray (Map)
88

9-
- (NSArray *)mapObjectsUsingBlock:(id (^)(id obj, NSUInteger idx))block {
9+
- (NSArray *)rnfs_mapObjectsUsingBlock:(id (^)(id obj, NSUInteger idx))block {
1010
NSMutableArray *result = [NSMutableArray arrayWithCapacity:[self count]];
1111
[self enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
1212
[result addObject:block(obj, idx)];

RNFSManager.m

+7-5
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
//
88

99
#import "RNFSManager.h"
10-
#import "RCTConvert.h"
1110
#import "RCTBridge.h"
1211
#import "NSArray+Map.h"
1312

@@ -18,6 +17,9 @@ @implementation RNFSManager
1817
@synthesize bridge = _bridge;
1918
RCT_EXPORT_MODULE();
2019

20+
- (dispatch_queue_t)methodQueue {
21+
return dispatch_queue_create("pe.lum.rnfs", DISPATCH_QUEUE_SERIAL);
22+
}
2123

2224
RCT_EXPORT_METHOD(readDir:(NSString*)directory inFolder:(NSNumber*)folder callback:(RCTResponseSenderBlock)callback){
2325
NSString *path;
@@ -31,11 +33,11 @@ @implementation RNFSManager
3133
}
3234

3335
NSFileManager *fileManager = [NSFileManager defaultManager];
34-
NSError *error;
36+
NSError *error = nil;
3537
NSString * dirPath = [path stringByAppendingPathComponent:directory];
3638
NSArray *contents = [fileManager contentsOfDirectoryAtPath:dirPath error:&error];
3739

38-
contents = [contents mapObjectsUsingBlock:^id(id obj, NSUInteger idx) {
40+
contents = [contents rnfs_mapObjectsUsingBlock:^id(id obj, NSUInteger idx) {
3941
return @{
4042
@"name": (NSString*)obj,
4143
@"path": [dirPath stringByAppendingPathComponent:(NSString*)obj]
@@ -50,7 +52,7 @@ @implementation RNFSManager
5052
}
5153

5254
RCT_EXPORT_METHOD(stat:(NSString*)filepath callback:(RCTResponseSenderBlock)callback){
53-
NSError *error;
55+
NSError *error = nil;
5456
NSDictionary *attributes = [[NSFileManager defaultManager] attributesOfItemAtPath:filepath error:&error];
5557

5658
if (error) {
@@ -86,7 +88,7 @@ @implementation RNFSManager
8688
if (!exists) {
8789
return callback(@[[NSString stringWithFormat:@"File at path %@ does not exist", filepath]]);
8890
}
89-
NSError *error;
91+
NSError *error = nil;
9092
BOOL success = [manager removeItemAtPath:filepath error:&error];
9193

9294
if (!success) {

0 commit comments

Comments
 (0)