NSString *name =[dataArray valueForKey:@"name"];
This doesn't do what you think it'll do. valueForKey:
, when sent to an array, returns an array of the values corresponding to the given key for all the items in the array. So, that line will assign an array of the "name" values for all the items in dataArray
despite the fact that you declared name
as a NSString
. Same goes for the subsequent lines.
What you probably want instead is:
for (NSManagedObject *item in dataArray) {
NSString *name = [item valueForKey:@"name"];
...
Better, if you have a NSManagedObject
subclass -- let's call it Person
representing the entity you're requesting, you can say:
for (Person *person in dataArray) {
NSString *name = person.name;
...
which leads to an even simpler version:
for (Person *person in dataArray) {
int response = [network sendName:person.name
withDateOfBirth:person.dob
andGender:person.gender
forID:person.id];
although I'd change the name of that method to leave out the conjunctions and prepositions. -sendName:dateOfBirth:gender:id:
is enough, you don't need the "with", "and", and "for."