Search code examples
iosobjective-cnsmutablearraynsmutableset

addObject not working with NSMutableSet


I've tried to add an Object to the NSMutableSet but it doesn't work where it perfectly works fine with NSMutableArray.

//doesn't Work

[arr_NSMutableSet addObject:Object];
NSLog(@"%@",arr_NSMutableSet); // Shows nil

//Works fine
[arr_NSMutableArray addObject:Object];
NSLog(@"%@",arr_NSMutableArray); // Shows result

How to add the Object in NSMutableSet?


Solution

  • arr_NSMutableSet is nil. You need to create it:

    arr_NSMutableSet = [NSMutableSet set];