0

Below is my code..

dataArray = [[response valueForKey:@"data"]mutableCopy];

NSPredicate *departmentPredicate =
[NSPredicate predicateWithFormat:@"department == %@",selectedDepartment];

doctorsArray =[[dataArray filteredArrayUsingPredicate:departmentPredicate]mutableCopy];             
doctorsNameArray = [[doctorsArray valueForKey:@"doctors"]mutableCopy];
doctorsListArray = [[doctorsNameArray valueForKey:@"name"]mutableCopy];

data array (4 elements)

<__NSArrayM 0x7ca81f10>(
{
department = Endodontics;
doctors =     (
            {
        id = 11;
        name = "Dr Alex";
    }
);
id = 7;
},
{
department = "Operative Dentistry";
doctors =     (
            {
        id = 9;
        name = "Dr  Amal K Ramachandran";
    },
            {
        id = 6;
        name = "Dr Rahman";
    },
            {
        id = 10;
        name = "Dr varsha";
    }
);
id = 8;
},
{
department = Othondontics;
doctors =     (
            {
        id = 8;
        name = "Dr. Rashid KC";
    },
            {
        id = 5;
        name = Prasad;
    }
);
id = 5;
},
{
department = Periodontics;
doctors =     (
            {
        id = 7;
        name = "Dr  Sreya Vishwanath";
    }
);
id = 6;
}
)

doctors array (1 element)

<__NSArrayM 0x7c9553e0>(
{
department = Othondontics;
doctors =     (
            {
        id = 8;
        name = "Dr. Rashid KC";
    },
            {
        id = 5;
        name = Prasad;
    }
);
id = 5;
}
)

doctors name array

<__NSArrayM 0x7c94ef10>(
<__NSArrayI 0x7c921ea0>(
{
id = 8;
name = "Dr. Rashid KC";
},
{
id = 5;
name = Prasad;
}
)

)

doctors list array (1 element)

<__NSArrayM 0x7b760ba0>(
<__NSArrayI 0x7ca836f0>(
Dr. Rashid KC,
Prasad
)

)

The problem is doctors array, doctor name array, doctors list array contains more than 1 elemnt, but stores as 1 element..

Rashid KC
  • 737
  • 1
  • 9
  • 17

1 Answers1

0

You can use Key-Value Coding Collection Operators. You can use the @unionOfArrays keyword here.

doctorsNameArray = [doctorsArray valueForKeyPath:@"@unionOfArrays.doctors"];

This will give you a single array combining all the doctor arrays of each element in doctorsArray

riadhluke
  • 880
  • 6
  • 18