Iterar over array of entity and get value of some key based on value of “other key” matche

前端 未结 2 1757
鱼传尺愫
鱼传尺愫 2021-01-22 03:47

I have an array of entity class (eg SubmittedAnswer). Its JSON format is look like as below.


{
\"submittedAnswers\": [{
    \"submittedQuestionId\": \"C7B3         


        
2条回答
  •  抹茶落季
    2021-01-22 04:16

    NSPredicate *predicate = [NSPredicate predicateWithFormat:@"submittedQuestionId == %@", yourSubmittedQuestionId];
    NSArray *filteredArray = [myArray filteredArrayUsingPredicate:predicate];
    id firstFoundObject = nil;
    if ([filteredArray count] > 0) {
        firstFoundObject = [filteredArray objectAtIndex:0];
    }
    

    Please make sure your SubmittedAnswer class has property submittedQuestionId

提交回复
热议问题