react-native-async-storage / async-storage

An asynchronous, persistent, key-value storage system for React Native.
https://react-native-async-storage.github.io/async-storage/
MIT License
4.68k stars 465 forks source link

Error using multimerge on ios #333

Closed bilicio closed 4 years ago

bilicio commented 4 years ago

Im using gunjs to bring data from database to asyncstorage. when trying to store data with multimerge the app crashes.

Expected behavior

enable to store the data

Repro steps

install react-native with react-native init install gun-asyncstorage install gun

initialize gun

try to import data from server

Environment

Exception '-[__NSCFString countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0x6000009e84e0' was thrown while invoking multiMerge on target AsyncLocalStorage with params ( ( ( "#", "\"k8hdinsc02jOWiJZlWSJOkS\"" ), ( ".", "\"k8hdinrt6bXbuxduBoDT\"" ), ( ":", "{\"#\":\"k8hdinrt6bXbuxduBoDT\"}" ), ( ">", 1585748171244 ) ), 1113 )

krizzu commented 4 years ago

Hey,

Could you provide more details repro steps? Or better yet, without using third party libs (so we can eliminate errors that come from them)

bilicio commented 4 years ago

sure, im trying to merge a single line with this: AsyncStorage.mergeItem("#", "\"antidoto\"")

it gives me this error:

Exception '-[NSTaggedPointerString countByEnumeratingWithState:objects:count:]: unrecognized selector sent to instance 0xc7b527206054eaf3' was thrown while invoking multiMerge on target AsyncLocalStorage with params ( ( ( "#", "\"antidoto\"" ) ), 3487 ) callstack: ( 0 CoreFoundation 0x00007fff23e3dcce __exceptionPreprocess + 350 1 libobjc.A.dylib 0x00007fff50b3b9b2 objc_exception_throw + 48 2 CoreFoundation 0x00007fff23e5e9f4 -[NSObject(NSObject) doesNotRecognizeSelector:] + 132

bilicio commented 4 years ago

maybe i cant use "#" as key to merge?

krizzu commented 4 years ago

I guess it's because merge expect an object as a value? Why you use merge in the first place?

bilicio commented 4 years ago

i found it @Krizzu , using JSON.stringify() on string like "any word" and use like this: AsyncStorage.mergeItem("#", JSON.stringify('any word') ) trigger the error, of course, JSON.stringify its for objects. but using like that AsyncStorage.mergeItem("#", 'any word' ) works. thank you :)