SwiftUI firebase ユーザ削除 firestoreデータ削除

1.Swiftでユーザ削除
2.Functionsでデータ削除

だと思ったけれど、Swiftからコレクションで削除できる

Firestoreを試してみた – Qiita

    let ref = defaultStore.collection("data")
    delete.delete(collection: ref){ error in
        if let error = error {
            print("Error updating document: \(error)")
        }else{
            print("Document successfully updated")
        }
    }
    


func delete(collection: CollectionReference, batchSize: Int = 100, completion: @escaping (Error?) -> ()){
    collection.limit(to: batchSize).getDocuments { (docset,error) in
        guard let docset = docset
            else{
                completion(error)
                return
        }
        guard docset.count > 0
            else{
                completion(nil)
                return
        }

        let batch = collection.firestore.batch()
        docset.documents.forEach {batch.deleteDocument($0.reference)}

        batch.commit { (batchError) in
            if let batchError = batchError {
                completion(batchError)
            }else{
                delete(collection: collection, batchSize: batchSize, completion: completion)
            }
        }
    }
}