how to add nil to nsmutablearray?

后端 未结 9 1291
-上瘾入骨i
-上瘾入骨i 2020-12-13 12:22
NSArray *array = [[NSArray alloc] initWithObjects:@\"ΕΛΤΑ\",
                      @\"ΕΛΤΑ COURIER\", @\"ACS\", @\"ACS ΕΞΩΤΕΡΙΚΟ\", 
                      @\"DHL\",          


        
9条回答
  •  隐瞒了意图╮
    2020-12-13 13:10

    If you must add a nil object to a collection, use the NSNull class:

    The NSNull class defines a singleton object used to represent null values in collection objects (which don’t allow nil values).

    Assuming "array" is of type NSMutableArray:

    ....
    [array addObject:[NSNumber numberWithInt:2];
    [array addObject:@"string"];
    [array addObject:[NSNull null]];
    

提交回复
热议问题