NSMutableArray addObject, нераспознанный селектор

Можно сделать это так или иначе.

помещает '&'; символ впереди и переменная, Вы являетесь передающими, становятся одними и теми же как свой источник. т.е.: можно передать ссылкой, вместо того, чтобы делать копию из него.

так

    $fred = 5;
    $larry = & $fred;
    $larry = 8;
    echo $fred;//this will output 8, as larry and fred are now the same reference.
5
задан Shamas S - Reinstate Monica 4 May 2017 в 05:02
поделиться

2 ответа

The lines:

// set up a new cities array
currentCities = [NSMutableArray init];

Should read:

// set up a new cities array
[currentCities init];

which should hopefully fix your problem. Instead of initializing your array, you're sending an init message to a class object, which doesn't do anything. Afterwards, you're currentCities pointer is still not initialized.

Even better would be to remove that line and change the 4th line such that you allocate and initialize all in one step:

NSMutableArray *currentCities = [[NSMutableArray alloc] init];
9
ответ дан 18 December 2019 в 14:48
поделиться

You need to call some sort of initializer on NSMutableArray, don't you? initWithCapacity, or something like that? Not sure what you get if you leave it off.

** Just tested it. Make it [[NSMutableArray alloc] init] and you will be fine.

3
ответ дан 18 December 2019 в 14:48
поделиться