how to add nil to nsmutablearray?

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


        
相关标签:
9条回答
  • 2020-12-13 13:08

    If you really want a Null-ish item in your collection, NSNull is there for that.

    0 讨论(0)
  • You can't add an object to an NSArray because that class is immutable. You have to use NSMutableArray if you want to change the array after it is created.

    0 讨论(0)
  • 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]];
    
    0 讨论(0)
提交回复
热议问题