0

How would I pick out certain part of NSMutableArray? One fielding array from server is 2012-09-01 09:00:00 America/Los_Angeles I am trying to get just the time. I was thinking turning it into a string and then getting it and then back into NSMutablearray to populate to tableview cells. I am still looking at documentation

Options I am thinking of: -subarrayWithRange: componentsSeparatedByString:

UPDATE: Here is what I am doing now to get the field of appointments

NSDictionary *json = [NSJSONSerialization JSONObjectWithData:responseData options:NSJSONReadingMutableContainers error:&error];

    NSDictionary* myslots =[json objectForKey:@"slots"];
    self.timesArray = [[NSMutableArray alloc] init];
    NSLog(@"allslots: %@", myslots);

    for (NSString *slotKey in myslots.allKeys) {
    NSDictionary *slot = [myslots valueForKey:slotKey];

        for (myDays in slot){

        if ([[self.myDays objectForKey:@"isReservable"] isEqualToNumber:[NSNumber numberWithInt:1]])

           [self.timesArray addObject:[self.myDays objectForKey:@"begin"]];

        //NSLog(@"This is the times count: %@", timesArray.count);

    }





    }
     NSLog(@"These are the times avail: %@", self.timesArray); 
     [self.tableView reloadData];
}

All I want eventually is an array of just the times. I am sorry if I am not being clear. I am trying to. Please let me know what information I can provide to paint a clearer picture

TIDev
  • 109
  • 4
  • 10
  • 1
    What? Are there multiple date strings in your array? Or what's that? –  Sep 02 '12 at 17:22
  • An NSMutableArray (or NSArray) is an ordered container for other objects. You're going to have to tell us what kind of object is actually **in** the array if you want us to tell you how to do something with its string representation. For example, if they are NSDate objects, there will be a much easier way to get just the time that doesn't involve string processing. – UIAdam Sep 02 '12 at 17:26
  • Array of dictionaries, each day is dictionary. Multiple time fields (appointment times) each day. 9-10, 10-11, 11-12, etc. So there are 9-1 9-10, 9-1 10-11 and so on – TIDev Sep 02 '12 at 17:27
  • You should give a concrete example of your input array and the desired result. – Martin R Sep 02 '12 at 17:34

1 Answers1

1

I'd save it as a string first

NSString *someString = [myArray objectAtIndex:index];

and then use something like NSMakeRange to get just that bit

[someString substringWithRange:NSMakeRange(11,18)];
Suiz Uzcategui
  • 145
  • 1
  • 8
  • When I try this it says [__NSArrayM objectAtIndex:]: index 2620692019 beyond bounds for empty array' I am working on figuring out why – TIDev Sep 02 '12 at 17:43
  • Not really. You do have to declare that placeholder "index" variable I put in there though. Your index number / iteration variable should go there. – Suiz Uzcategui Sep 02 '12 at 17:44
  • [__NSArrayM objectAtIndex:index]; The index goes inside the brackets as far as I know. – Suiz Uzcategui Sep 02 '12 at 17:44
  • I am using for statements (fast enumeration) so I don't have iteration variables as far as I know – TIDev Sep 02 '12 at 17:49
  • You could add an index variable and increase it manually. See this thread for additional information http://stackoverflow.com/questions/8113482/keep-track-of-index-in-fast-enumeration – Suiz Uzcategui Sep 02 '12 at 17:50
  • Can we move to chat so I can explain what it is now doing? – TIDev Sep 02 '12 at 17:53
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/16159/discussion-between-tidev-and-suiz-uzcategui) – TIDev Sep 02 '12 at 17:54
  • Thanks for taking the extra time in chat to help me out – TIDev Sep 02 '12 at 18:14