ios – Deleting from Firebase with Document ID


I’m using Firebase to store and retrive Data. Im able to suceculllty save data to Firestore but nothing seems to happen when i delete the user from the firestorm.

Initially when the user creates an object (Package)

let newPackage = PackageObject(context: self.context)
//Set Package properties
newPackage.trackingNumber = trackingNumberLabel.text!
newPackage.packageDescription = packageDescriptionLabel.text
newPackage.packageCarrier = carrierNameLabel.text!
newPackage.circleIndicatorColor = StringLiteral.redColor
newPackage.currentDescription =  StringLiteral.defaultDescription
newPackage.carrierLogoName = carrierNameLabel.text! = randomString(length: 20)

let homeInstance = HomeViewController() // New HomeViewController Instance
homeInstance.addPackageObject(newObject: newPackage) // Add tracking Number
homeInstance.requestData(newTrackingNumber: newPackage)            

Core Data Class

//MARK: - CoreData and Related Functions
extension HomeViewController
    func addPackageObject(newObject: PackageObject)
        CoreDataManager.sharedManager.insertPackageObject(newObject: newObject) //Add Object to Core Data
        addTrackingNumberToFirebase(newObject: newObject) // Add Object to Firebase Database
    func deletePackageObject(deleteObject: PackageObject)
        deletePackageFromFirebase(newObject: deleteObject)
        CoreDataManager.sharedManager.delete(person: deleteObject) //Delete Package Object from Core Data
    func loadPackageObject() -> [PackageObject]
        return CoreDataManager.sharedManager.loadTrackingNumber()

    func saveTrackingNumber()


Firebase Helper

extension HomeViewController
    func addTrackingNumberToFirebase(newObject: PackageObject)
        let dict = [
            "tracking_Number": newObject.trackingNumber!,
                    "package_Description": newObject.packageDescription!,
                    "package_Carrier": newObject.packageCarrier!,
                    "circle_Indicator_Color": newObject.circleIndicatorColor!,
                    "current_Description": newObject.currentDescription!,
                    "carrier_LogoName": newObject.carrierLogoName!
       // db.collection("tracking_Numbers").addDocument(data: dict) //Add without Custom ID
        db.collection("tracking_Numbers").document(!).setData(dict) //Add Document with ID
    func deletePackageFromFirebase(newObject: PackageObject)

For some reason my data is not being deleted from fire base

Here is my Firebase rules

rules_version = '2';
service cloud.firestore 
  match /databases/{database}/documents 
    match /{document=**} 
      allow read, write: if true;
// Make sure the uid of the requesting user matches name of the user
    // document. The wildcard expression {userId} makes the userId variable
    // available in rules.
// match /users/{userId} {
//       allow read, update, delete: if request.auth != null && request.auth.uid == userId;
//       allow create: if request.auth != null;
//     }


Is there something im missing


Source link

Leave a Reply

Your email address will not be published.