fetch specific data from firebase for different users

I have two users that are trying to send data to each other. One user posts a task while the other is trying to complete a task.

The user who is trying to complete the task can successfully send all different types of enum data to the user who posted the job, but the user who accepted the user to complete the task can only send one notification.

A simple enum that I have created looks like,

   class userNotifications {

// MARK: - establish notificationTypes

enum NotificationType: Int, Printable {
    
    case swipe
    case accepted
    case inProgress
    case completed
    case pay
    case reported
    case something

    var description: String {
        switch self {
        case .swipe: return " swiped on your Job "
        case .accepted: return " accepted you to complete the job, "
        case .inProgress: return " is in progress to complete the job, "
        case .completed: return " completed "
        case .pay: return " rated and paid you for your work"
        case .reported: return " Your job was reported. We will review your job and reach out"
        case .something : return "something else"

        }
    }
    
    init(index: Int) {
        switch index {
        case 0: self = .swipe
        case 1: self = .accepted
        case 2: self = .inProgress
        case 3: self = .completed
        case 4: self = .pay
        case 5: self = .reported
        default: self = .swipe
        }
    }
}

// MARK: - access firebaseData

var creationDate: Date!
var timeDate: Date!
var uid: String!
var fromId: String?
var workerId: String?
var user: User!
var poster: Poster!
var type: Int?
var notificationType: NotificationType!
var didCheck = false

init(user: User? = nil, poster: Poster? = nil, dictionary: Dictionary<String, AnyObject>) {
    
    self.user = user
    
    if let poster = poster {
        self.poster = poster
    }
    
    if let swipeDate = dictionary["Swipe Date"] as? Double {
        self.creationDate = Date(timeIntervalSince1970: swipeDate)
    }
    
    if let createDate = dictionary["creationDate"] as? Double {
               self.creationDate = Date(timeIntervalSince1970: createDate)
           }
    
    if let swipeDate = dictionary["time&date"] as? Double {
            self.timeDate = Date(timeIntervalSince1970: swipeDate)
        }
    
    if let type = dictionary["type"] as? Int {
        self.notificationType = NotificationType(index: type)
    }
    
    if let fromId = dictionary["fromId"] as? String {
        self.fromId = fromId
    }
    
    if let workerId = dictionary["workerId"] as? String {
              self.workerId = workerId
          }

    if let checked = dictionary["checked"] as? Int {
        if checked == 0 {
            self.didCheck = false
        } else {
            self.didCheck = true
        }
    }
  }
 }

And the code that I am using to retrieve the data from firebase is

func fetchNotifications() {
    guard let currentUID = Auth.auth().currentUser?.uid else { return }
    NOTIFICATIONS_REF.child(currentUID).observeSingleEvent(of: .value) { (snapshot) in
        guard let dictionary = snapshot.value as? Dictionary<String, AnyObject> else { return }
        let notificationId = snapshot.key
        for (_, postingRawData) in dictionary {
            guard let postingDictionary = postingRawData as? Dictionary<String, AnyObject> else { continue }
            guard let type = postingDictionary["type"] as? Int else { continue }
            guard let uid = (type == userNotifications.NotificationType.accepted.rawValue) ? postingDictionary["fromId"] as? String : postingDictionary["workerId"] as? String else { continue }
            Database.fetchUser(with: uid, completion: { (user) in
                if let postId = postingDictionary["fromId"] as? String {
                    Database.fetchPoster(with: postId, completion: {(poster) in
                        let notification = userNotifications(user: user, poster: poster, dictionary: postingDictionary)
                        self.notifications.append(notification)
                        self.handleSortNotification()
                    })
                } else {
                    let notification = userNotifications(user: user, dictionary: postingDictionary)
                    self.notifications.append(notification)
                    self.handleSortNotification()
                }
            })
        }
    }
}

Now in the code above, I had to use the code

 guard let uid = (type == userNotifications.NotificationType.accepted.rawValue) ? postingDictionary["fromId"] as? String : postingDictionary["workerId"] as? String else { continue } 

Without this line, The only user that was receiving the notifications was the user who posted the job. This user can receive case 0,2,3 and 5.

While the user who completed the task is supposed to receive the notifications 1 and 4.

without

 guard let uid = (type == userNotifications.NotificationType.accepted.rawValue) ? postingDictionary["fromId"] as? String : postingDictionary["workerId"] as? String else { continue }

The user who completed the task doesn’t receive a notification at all. I understand else statements, but that won’t work in this particular statement. Is there a way for me to receive both notificationType .accepted and .pay? Im not sure how to manipulate this line into receiving both. If I change the type == to .pay, it will still call the .accepted and only that. Both of these notification types save successfully into firebase. just not sure why they arent retrieving properly.

Source: Ios Questions