create random id without no childByAutoId firebase

i what to create a random ID to an object in firebase, i know i can use childByAutoId, but is there any other way to create a random ID with firebase database.

I know it's possible to create a random number with arc4random() in swift and that works, but is there a better solution?

Upvotes: 0

Views: 305

Answers (1)

Micah Simmons
Micah Simmons

Reputation: 2158

You can use something like this:

let uniqueID = "\(NSDate().timeIntervalSince1970 * 1000)\(arc4random())"

That would give you the current unix time in milliseconds concatenated with a random number and guarantee a new unique ID every millisecond.

I think you can also get unix time directly from Firebase too.

Upvotes: 1

Related Questions