0

< SOLVED >

I created my project using Xcode 6. I had such a piece of code there:

.h file:

@property (weak, nonatomic) IBOutlet UIImageView *imageView1;
@property (weak, nonatomic) IBOutlet UIImageView *imageView2;
@property (weak, nonatomic) IBOutlet UIImageView *imageView3;
@property (weak, nonatomic) IBOutlet UIImageView *imageView4;
@property (weak, nonatomic) IBOutlet UIImageView *imageView5;
@property (weak, nonatomic) IBOutlet UIImageView *imageView6;
@property (weak, nonatomic) IBOutlet UIImageView *imageView7;

.m file:

self.featureViews = [NSMutableArray array];
[self.featureViews addObject:self.imageView1];
[self.featureViews addObject:self.imageView2];
[self.featureViews addObject:self.imageView3];
[self.featureViews addObject:self.imageView4];
[self.featureViews addObject:self.imageView5];
[self.featureViews addObject:self.imageView6];
[self.featureViews addObject:self.imageView7];

All image views were created using the interface builder and everything worked fine.

But recently I updated to Xcode 7, and I had a necessity to add one more UIImageView.

I did totally the same thing: created the imageView8 in IB, created a new referencing outlet and added the following string

[self.featureViews addObject:self.imageView8];

To my great astonishment now the app falls with the -[__NSArrayM insertObject:atIndex:]: object cannot be nil error when adding imageView8.

2015-09-22 16:20:13.063 XXX[1752:38656] **Image view 7 <UIImageView: 0x7f8396bd2e40; frame = (251 6; 33 33); autoresize = RM+BM; userInteractionEnabled = NO; layer = <CALayer: 0x7f8396bd2fe0>>**
2015-09-22 16:20:13.064 XXX[1752:38656] **Image view 8 (null)**

Does anyone have any idea why this may happen?

Update

I just simply had to reset the iOS simulator and perform a full build to solve the problem...

iOS Unit
  • 218
  • 4
  • 8
  • in Xcode 7 you need to set all IBOutlet to strong ownership qualifier. – Ashish P. Sep 22 '15 at 13:40
  • 1
    Did you connect the outlets? Also, you could use an `IBOutletCollection` – Sulthan Sep 22 '15 at 13:41
  • 5
    @AshishP That's definitely not true. – Sulthan Sep 22 '15 at 13:42
  • Also you can use IBOutleCollection in such cases http://nshipster.com/ibaction-iboutlet-iboutletcollection/ – Igor Sep 22 '15 at 13:46
  • plz check link http://stackoverflow.com/questions/7678469/should-iboutlets-be-strong-or-weak-under-arc what apple engineer said in session from WWDC 2015 – Ashish P. Sep 22 '15 at 13:48
  • Yes, all outlets are connected. – iOS Unit Sep 22 '15 at 13:56
  • 1
    Using IBOutletCollection seems to be reasonable, but it's written the order is not guaranteed there, which is critical in my case – iOS Unit Sep 22 '15 at 13:58
  • Changing properties to strong did not make any affect – iOS Unit Sep 22 '15 at 13:59
  • The error indicates that imageView8 is null. If it is properly connected, as you seem to think, then first step would be to delete the app on the simulator/device and then do a full build and run to make sure it is not a deployment glitch. If that fails, then I would recheck your connections. – Rory McKinnel Sep 22 '15 at 14:03
  • Thanks Rory, resetting and rebuilding did work. I just never thought that such things may happen because of a deployment glitch – iOS Unit Sep 22 '15 at 14:14
  • Excellent. Sadly it happens a lot. You would hope newer versions of xcode would have fixed this. Sometimes a build clean/rebuild is enough, but often it needs the app deleted. – Rory McKinnel Sep 22 '15 at 14:27

0 Answers0