ios - How to add/sum hours from array in Objective C -
i new ios programming , stuck on simple cant find answer anywhere ...i need pls. have array , has hours store in like- 11:30 13:45 18:00 23:05 how can add/sum ?
thanks in advance.
how this:
nsinteger total = 0; nsarray *arr = @[@"11:30", @"13:45", @"18:00", @"23:05"]; (nsstring *anhour in arr) { nsarray *splitstring = [anhour componentsseparatedbystring:@":"]; nsinteger minutes = [splitstring[0] integervalue]*60 + [splitstring[1] integervalue]; total += minutes; } nslog(@"total hours are: %f",total/60.0);
Comments
Post a Comment