简体   繁体   中英

How to add String from one array to another

I can't seem to append a string from arrayOne into arrayTwo. It's a very simple problem and I have Googled around and have tried different examples that I found below. Does anyone see the obvious issue here?

[_arrayTwo addObject:arrayOne[i]]; // int i
[_arrayTwo addObject:[arrayOne objectAtIndex:i]]; // int i
[_arrayTwo addObject:@"Test"]; // I can't even add a literal string

NSString *tempString = [arrayOne objectAtIndex:i];
[arrayTwo addObject:tempString];

NSLog Output:

NSLog(@"%@", _imageArray); // Result is "(null)"

Additional Notes:

  1. arrayOne is healthy (contains NSString values)
  2. Both arrays are NSMutableArray (declared as properties in the .h)

I believe _imageArray is nil

Try adding in

_imageArray = [[NSMutableArray alloc] init];

In your init method call.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM