2

I am currently trying to store the value NaN in Firebase.

Here is my setup:

The value is let varname = Double.nan;

I am setting the value by calling FIRDatabase.database().reference(withPath: "test").setValue(varname);

But I am getting the following error:

'InvalidFirebaseData', reason: '(setValue:) Cannot store NaN at path: varname.'

Is there a different way I should be saving this NaN?

Paulo Mattos
  • 18,845
  • 10
  • 77
  • 85
Jake Chasan
  • 6,290
  • 9
  • 44
  • 90

1 Answers1

5

Data in Firebase Databases are stored as JSON, and JSON cannot contain NaN.

The best you can do is to store "NaN" or some other value that you translate to NaN on read. (A bit impractical, so perhaps you should reconsider whether you really want NaN in your database.)

Community
  • 1
  • 1
ArneHugo
  • 6,051
  • 1
  • 26
  • 47