Adding nil to NSMutableArray
Posted
by ayanonagon
on Stack Overflow
See other posts from Stack Overflow
or by ayanonagon
Published on 2010-06-08T14:19:08Z
Indexed on
2010/06/08
14:22 UTC
Read the original article
Hit count: 241
objective-c
|nsmutablearray
I am trying to create a NSMutableArray by reading in a .txt file and am having trouble setting the last element of the array to nil.
NSString *filePath = [[NSBundle mainBundle] pathForResource:@"namelist" ofType:@"txt"];
NSString *data = [NSString stringWithContentsOfFile:filePath encoding:NSUTF8StringEncoding error:nil];
NSArray *list = [data componentsSeparatedByString:@"\n"];
NSMutableArray *mutableList = [[NSMutableArray alloc] initWithArray:list];
I wanted to use NSMutableArray's function addObject, but that will not allow me to add nil. I also tried:
[mutableList addObject:[NSNull null]];
but that does not seem to work either. Is there a way around this problem?
© Stack Overflow or respective owner