user979331
user979331

Reputation: 11851

Objective-C check if item exists in NSMutableArray

I have this section of code here:

for (int i = 0; i<[taskData count]; i++)
    {
        for (int j=0; j<[allJobTaskArray count]; j++)
        {
            NSLog(@"%d", i);
            NSLog(@"%d", j);
            PunchListDataCell *pldCell = [[[PunchListDataCell alloc]init] autorelease];
            pldCell.stringData= [self reverseStringDate:[[[allJobTaskArray objectAtIndex:j] objectAtIndex:i] substringToIndex:10]];
            pldCell.cellSelected = NO;
            [punchListData addObject:pldCell];
        }

    }

Now let me explain:

I have tried the following:

if([[allJobTaskArray objectAtIndex:j] objectAtIndex:i] == [NSNull null]){
                pldCell.stringData = @"";
            }else{
                pldCell.stringData= [self reverseStringDate:[[[allJobTaskArray objectAtIndex:j] objectAtIndex:i] substringToIndex:10]];
            }

Upvotes: 2

Views: 219

Answers (1)

tpatiern
tpatiern

Reputation: 415

Altogether it should look something like -

for (int i = 0; i<[taskData count]; i++)
    {
        for (int j=0; j<[allJobTaskArray count]; j++)
        {
            NSLog(@"%d", i);
            NSLog(@"%d", j);


            PunchListDataCell *pldCell = [[[PunchListDataCell alloc]init] autorelease];
            if ([[allJobTaskArray objectAtIndex:j] count] > i) {                    
                pldCell.stringData= [self reverseStringDate:[[[allJobTaskArray objectAtIndex:j] objectAtIndex:i] substringToIndex:10]];
            } else {
                pldCell.stringData = @"";
            }

            pldCell.cellSelected = NO;
            [punchListData addObject:pldCell];
        }
    }

Upvotes: 1

Related Questions