I'd like to print number of elements and one of element in NSLog. I create new dictionary variable and add it to the NSMutableArray. Then in NSLog I'd like to see content of an element but it returns null and zero elements. My code is below:
while (![scanner isAtEnd])
{
NSString *indexString;
(void) [scanner scanUpToCharactersFromSet:[NSCharacterSet newlineCharacterSet] intoString:&indexString];
NSString *startString;
(void) [scanner scanUpToString:@" --> " intoString:&startString];
// My string constant doesn't begin with spaces because scanners
// skip spaces and newlines by default.
(void) [scanner scanString:@"-->" intoString:NULL];
NSString *endString;
(void) [scanner scanUpToCharactersFromSet:[NSCharacterSet newlineCharacterSet] intoString:&endString];
NSString *textString;
// (void) [scanner scanUpToCharactersFromSet:[NSCharacterSet newlineCharacterSet] intoString:&textString];
// BEGIN EDIT
(void) [scanner scanUpToString:@"\r\n\r\n" intoString:&textString];
textString = [textString stringByReplacingOccurrencesOfString:@"\r\n" withString:@" "];
// Addresses trailing space added if CRLF is on a line by itself at the end of the SRT file
textString = [textString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]];
// END EDIT
NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys:
indexString, @"index",
startString, @"start",
endString , @"end",
textString , @"text",
nil];
[subtitlesArray addObject:dictionary];
NSLog(@"%@", dictionary);
}
[subtitlesArray addObject:nil];
// Insert code here to initialize your application
NSLog(@"%lu", [subtitlesArray count]);
// for example
NSLog(@"%@", [subtitlesArray objectAtIndex: 7]);
//And here I get 0 and null
}