I have an NSMutableArray named randomSelection:
NSMutableArray *randomSelection;
I am then trying to add strings to this array if certain c
Just allocate your NSMutableArray. You'll get solved your problem.
Try this:
NSMutableArray *randomSelection = [[NSMutableArray alloc]init];
[randomSelection addObject:@"string1"];
First allocate the array using following statement & then objects in it.
NSMutableArray *randomSelection = [[NSMutableArray alloc] init];
[randomSelection addObject:[NSString stringWithFormat:@"String1"]];
[randomSelection addObject:[NSString stringWithFormat:@"String2"]];
NSLog(@"Array - %@", randomSelection);
This will definitely solves your problem.
I think you are missing to allocate the memory for array. So try this
NSMutableArray *randomSelection = [[NSMutableArray alloc] init];
[randomSelection addObject:@"string1"];
NSString *test = [randomSelection objectAtIndex:0];
NSLog(test);
NSMutableArray *randomSelection = [[NSMutableArray alloc]init];
[randomSelection addObject:@"string1"];
You need to alloc it first.
Swift :
var randomSelection: [AnyObject] = [AnyObject]()
randomSelection.append("string1")
let test: String = randomSelection[0] as! String
print(test)
OR
let array : NSMutableArray = []
array.addObject("test String")
print(array)