Skip to content

Commit 0b14c5a

Browse files
committed
Split RNCAsyncStorageDelegate impl from AppDelegate
1 parent 5e6e1d2 commit 0b14c5a

File tree

5 files changed

+88
-57
lines changed

5 files changed

+88
-57
lines changed

example/ios/AsyncStorageExample.xcodeproj/project.pbxproj

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
13B07FBF1A68108700A75B9A /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 13B07FB51A68108700A75B9A /* Images.xcassets */; };
2222
13B07FC11A68108700A75B9A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 13B07FB71A68108700A75B9A /* main.m */; };
2323
146834051AC3E58100842450 /* libReact.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 146834041AC3E56700842450 /* libReact.a */; };
24+
196F5D682254C1530035A6D3 /* AppDelegate+RNCAsyncStorageDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 196F5D672254C1530035A6D3 /* AppDelegate+RNCAsyncStorageDelegate.m */; };
2425
3D82E3B72248BD39001F5D1A /* libRNCAsyncStorage.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 3DC5398C220F2C940035D3A3 /* libRNCAsyncStorage.a */; };
2526
832341BD1AAA6AB300B99B32 /* libRCTText.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 832341B51AAA6A8300B99B32 /* libRCTText.a */; };
2627
ADBDB9381DFEBF1600ED6528 /* libRCTBlob.a in Frameworks */ = {isa = PBXBuildFile; fileRef = ADBDB9271DFEBF0700ED6528 /* libRCTBlob.a */; };
@@ -320,6 +321,8 @@
320321
13B07FB61A68108700A75B9A /* Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = Info.plist; path = AsyncStorageExample/Info.plist; sourceTree = "<group>"; };
321322
13B07FB71A68108700A75B9A /* main.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = main.m; path = AsyncStorageExample/main.m; sourceTree = "<group>"; };
322323
146833FF1AC3E56700842450 /* React.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = React.xcodeproj; path = "../../node_modules/react-native/React/React.xcodeproj"; sourceTree = "<group>"; };
324+
196F5D672254C1530035A6D3 /* AppDelegate+RNCAsyncStorageDelegate.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = "AppDelegate+RNCAsyncStorageDelegate.m"; path = "AsyncStorageExample/AppDelegate+RNCAsyncStorageDelegate.m"; sourceTree = "<group>"; };
325+
196F5D8E2254C2C90035A6D3 /* AppDelegate+RNCAsyncStorageDelegate.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; name = "AppDelegate+RNCAsyncStorageDelegate.h"; path = "AsyncStorageExample/AppDelegate+RNCAsyncStorageDelegate.h"; sourceTree = "<group>"; };
323326
2D16E6891FA4F8E400B85C8A /* libReact.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; path = libReact.a; sourceTree = BUILT_PRODUCTS_DIR; };
324327
3DC5395A220F2C940035D3A3 /* RNCAsyncStorage.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RNCAsyncStorage.xcodeproj; path = ../../ios/RNCAsyncStorage.xcodeproj; sourceTree = "<group>"; };
325328
5E91572D1DD0AC6500FF2AA8 /* RCTAnimation.xcodeproj */ = {isa = PBXFileReference; lastKnownFileType = "wrapper.pb-project"; name = RCTAnimation.xcodeproj; path = "../../node_modules/react-native/Libraries/NativeAnimation/RCTAnimation.xcodeproj"; sourceTree = "<group>"; };
@@ -423,6 +426,8 @@
423426
008F07F21AC5B25A0029DE68 /* main.jsbundle */,
424427
13B07FAF1A68108700A75B9A /* AppDelegate.h */,
425428
13B07FB01A68108700A75B9A /* AppDelegate.m */,
429+
196F5D8E2254C2C90035A6D3 /* AppDelegate+RNCAsyncStorageDelegate.h */,
430+
196F5D672254C1530035A6D3 /* AppDelegate+RNCAsyncStorageDelegate.m */,
426431
13B07FB51A68108700A75B9A /* Images.xcassets */,
427432
13B07FB61A68108700A75B9A /* Info.plist */,
428433
13B07FB11A68108700A75B9A /* LaunchScreen.xib */,
@@ -957,6 +962,7 @@
957962
files = (
958963
13B07FBC1A68108700A75B9A /* AppDelegate.m in Sources */,
959964
13B07FC11A68108700A75B9A /* main.m in Sources */,
965+
196F5D682254C1530035A6D3 /* AppDelegate+RNCAsyncStorageDelegate.m in Sources */,
960966
);
961967
runOnlyForDeploymentPostprocessing = 0;
962968
};
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#import "AppDelegate.h"
9+
10+
#import <RNCAsyncStorage/RNCAsyncStorageDelegate.h>
11+
12+
@interface AppDelegate (RNCAsyncStorageDelegate) <RNCAsyncStorageDelegate>
13+
@end
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/**
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#import "AppDelegate+RNCAsyncStorageDelegate.h"
9+
10+
#import <RNCAsyncStorage/RNCAsyncStorage.h>
11+
12+
@implementation AppDelegate (RNCAsyncStorageDelegate)
13+
14+
- (void)allKeys:(nonnull RNCAsyncStorageResultCallback)completion
15+
{
16+
completion(self.memoryStorage.allKeys);
17+
}
18+
19+
- (void)mergeValues:(nonnull NSArray<NSString *> *)values
20+
forKeys:(nonnull NSArray<NSString *> *)keys
21+
completion:(nonnull RNCAsyncStorageResultCallback)block
22+
{
23+
[NSException raise:@"Unimplemented"
24+
format:@"%@ is unimplemented", NSStringFromSelector(_cmd)];
25+
}
26+
27+
- (void)removeAllValues:(nonnull RNCAsyncStorageCompletion)completion
28+
{
29+
[self.memoryStorage removeAllObjects];
30+
completion(nil);
31+
}
32+
33+
- (void)removeValuesForKeys:(nonnull NSArray<NSString *> *)keys
34+
completion:(nonnull RNCAsyncStorageResultCallback)completion
35+
{
36+
for (NSString *key in keys) {
37+
[self.memoryStorage removeObjectForKey:key];
38+
}
39+
completion(@[]);
40+
}
41+
42+
- (void)setValues:(nonnull NSArray<NSString *> *)values
43+
forKeys:(nonnull NSArray<NSString *> *)keys
44+
completion:(nonnull RNCAsyncStorageResultCallback)completion
45+
{
46+
for (NSUInteger i = 0; i < values.count; ++i) {
47+
NSString *value = values[i];
48+
NSString *key = keys[i];
49+
[self.memoryStorage setObject:value forKey:key];
50+
}
51+
completion(@[]);
52+
}
53+
54+
- (void)valuesForKeys:(nonnull NSArray<NSString *> *)keys
55+
completion:(nonnull RNCAsyncStorageResultCallback)completion
56+
{
57+
NSMutableArray *values = [NSMutableArray arrayWithCapacity:keys.count];
58+
for (NSString *key in keys) {
59+
NSString *value = self.memoryStorage[key];
60+
[values addObject:value == nil ? [NSNull null] : value];
61+
}
62+
completion(values);
63+
}
64+
65+
@end

example/ios/AsyncStorageExample/AppDelegate.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,9 @@
77

88
#import <UIKit/UIKit.h>
99

10-
#import <RNCAsyncStorage/RNCAsyncStorageDelegate.h>
11-
12-
@interface AppDelegate : UIResponder <UIApplicationDelegate, RNCAsyncStorageDelegate>
10+
@interface AppDelegate : UIResponder <UIApplicationDelegate>
1311

1412
@property (nonatomic, strong) UIWindow *window;
13+
@property (nonatomic, strong) NSMutableDictionary<NSString *, NSString *> *memoryStorage;
1514

1615
@end

example/ios/AsyncStorageExample/AppDelegate.m

Lines changed: 2 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77

88
#import "AppDelegate.h"
99

10+
#import "AppDelegate+RNCAsyncStorageDelegate.h"
11+
1012
#import <RNCAsyncStorage/RNCAsyncStorage.h>
1113
#import <React/RCTBundleURLProvider.h>
1214
#import <React/RCTDevMenu.h>
1315
#import <React/RCTRootView.h>
1416

1517
@implementation AppDelegate {
16-
NSMutableDictionary<NSString *, NSString *> *_memoryStorage;
1718
__weak RCTBridge *_bridge;
1819
}
1920

@@ -90,57 +91,4 @@ - (BOOL)application:(UIApplication *)app
9091
return YES;
9192
}
9293

93-
#pragma mark - RNCAsyncStorageDelegate
94-
95-
- (void)allKeys:(nonnull RNCAsyncStorageResultCallback)completion
96-
{
97-
completion(_memoryStorage.allKeys);
98-
}
99-
100-
- (void)mergeValues:(nonnull NSArray<NSString *> *)values
101-
forKeys:(nonnull NSArray<NSString *> *)keys
102-
completion:(nonnull RNCAsyncStorageResultCallback)block
103-
{
104-
[NSException raise:@"Unimplemented"
105-
format:@"%@ is unimplemented", NSStringFromSelector(_cmd)];
106-
}
107-
108-
- (void)removeAllValues:(nonnull RNCAsyncStorageCompletion)completion
109-
{
110-
[_memoryStorage removeAllObjects];
111-
completion(nil);
112-
}
113-
114-
- (void)removeValuesForKeys:(nonnull NSArray<NSString *> *)keys
115-
completion:(nonnull RNCAsyncStorageResultCallback)completion
116-
{
117-
for (NSString *key in keys) {
118-
[_memoryStorage removeObjectForKey:key];
119-
}
120-
completion(@[]);
121-
}
122-
123-
- (void)setValues:(nonnull NSArray<NSString *> *)values
124-
forKeys:(nonnull NSArray<NSString *> *)keys
125-
completion:(nonnull RNCAsyncStorageResultCallback)completion
126-
{
127-
for (NSUInteger i = 0; i < values.count; ++i) {
128-
NSString *value = values[i];
129-
NSString *key = keys[i];
130-
[_memoryStorage setObject:value forKey:key];
131-
}
132-
completion(@[]);
133-
}
134-
135-
- (void)valuesForKeys:(nonnull NSArray<NSString *> *)keys
136-
completion:(nonnull RNCAsyncStorageResultCallback)completion
137-
{
138-
NSMutableArray *values = [NSMutableArray arrayWithCapacity:keys.count];
139-
for (NSString *key in keys) {
140-
NSString *value = _memoryStorage[key];
141-
[values addObject:value == nil ? [NSNull null] : value];
142-
}
143-
completion(values);
144-
}
145-
14694
@end

0 commit comments

Comments
 (0)