yandex
loader

please wait

  • Amie Khalifa Feb-12-2019 06:47:25 AM ( 1 month ago )

     

    I am trying to filter the array which consist of array and dictionary inside it. I want to filter based on the type of the service and then whose isPrimaryMailbox is Yes under attributes array. This is what I have done:-

     
    let services = Manager.realm().objects(Service.self).filter("type = %@", "MAILBOX")
    
            let serviceWithPrimaryEmail = services.filter({$0.attributes.first?.value == "Yes"})

    But this is showing the data which has isPrimaryMailbox value is No

    Below is the json response :-

    {
      "data": {
        "cust": [
          {
            "customerId": "2040349110",
            "serv": [
              {
                "bill": "2010007656959",
                "services": [
                  {
    "type": "MOBILE",
                    "status": "ACTIVE",
                    "plan": {
                      "name": "Mobil"
                    },
                    "addOns": [
                      {
                        "status": "Active"
                      }
                    ],
                    "hardware": [
                      {
                        "type": "HANDSET"
                      }
                    ]
                  },
                  {
                    "type": "MOBILE",
                    "plan": {
                      "name": "Mobile Service"
                    },
                    "addOns": [
                      {
                        "status": "Active"
                      }
                    ],
                    "hardware": [
                      {
                        "type": "HANDSET",
                      }
                    ]
                  },
                  {
                    "type": "MAILBOX",
                    "plan": {
                      "name": "Service"
                    },
                    "attributes": [
                      {
                        "name": "mailboxSize",
                        "value": "1 GB"
                      },
                      {
                        "name": "isPrimaryMailbox",
                        "value": "Yes"
                      }
                    ]
                  },
                  {
                    "type": "MAILBOX",
                    "status": "ACTIVE",
                    "plan": {
                      "name": "Service"
                    },
                    "attributes": [
                      {
                        "name": "mailboxSize",
                        "value": "1 GB"
                      },
                      {
                        "name": "isPrimaryMailbox",
                        "value": "No"
                      }
                    ]
                  }
                ]
              }
            ]
          }
        ]
      }
    
  • NeelKamal Jha Feb-12-2019 06:48:36 AM ( 1 month ago )

    You are always considering the first attribute, you have to refilter the $0.attributes to return isPrimaryMailbox and then check its value.

Please login

Similar Discussion

Recommended For You