0
  let saveDocument = Firestore.firestore()
  let docId = UserDefaults.standard.object(forKey: "docId") as! String
    print(docId)
 if let documentRefString = saveDocument.collection("Posts").document(docId) {}

at let documentRefString error message camee out.

Initializer for conditional binding must have Optional type, not 'DocumentReference' 

Tell me How to fix this error.

Jawad Ali
  • 13,556
  • 3
  • 32
  • 49
uizprg
  • 19
  • 9

1 Answers1

1

Remove if Let because documentRefString is not optional ... and you cant apply if let on non optionals

saveDocument.collection("Posts").document(docId)

Does not return optional value so change this line to

let documentRefString = saveDocument.collection("Posts").document(docId)

And use documentRefString safely

Jawad Ali
  • 13,556
  • 3
  • 32
  • 49