3

Encountering a strange issue debugging some code on Xcode 6.1 where the value of an NSArray I am debugging has objects yet the debugger shows nothing when inspecting individual elements. Here's what I am seeing in the debugger...

enter image description here

The kPatternDifficulties array is being filled used the following line of code...

NSArray *kPatternDifficulties = [self.definition objectForKey:@"pattern-difficulties"];

Usually when I see something like this I find a great cursory check is whether optimizations are turned on for the particular scheme/configuration being run. In this case turning off optimizations did nothing. As a next step I had figured this might be a memory issue perhaps the contents of self.definition being autoreleased ahead of time so I tried switching the above line to a copy instead of an assignemnt...

NSArray *kPatternDifficulties = [NSArray arrayWithArray:[self.definition objectForKey:@"pattern-difficulties"]];

And that works. I can correctly see all the elements of the NSArray so I have a solution which is great. I do have some questions such as...

  • This is causing a crash on iOS8 devices only. Previous iOS versions seem to fail silently would there be something notable around memory management changed in iOS8 that might be a reason for this?
  • What would be the general convention/standard around a case like this? Is it acceptable to assign to a variable or would a copy be the more correct approach? I'm reading an NSArray out of self.definition which is retained by the object itself so I don't think it should be released in anyway till the object is released and yet there does seem to an issue accessing this memory as is.
Rob Segal
  • 7,033
  • 12
  • 41
  • 68
  • Have you tried setting a breakpoint and using "po kPatternDifficulties" in the debug console? Sometimes when I can't see the data that I'm looking for printing the object in the console works for me. – Aron C Dec 09 '14 at 21:04
  • Yep did try that and that is a good point in that it does indeed print the value of the array with correct contents. Not seeing the contents of the array in the watch window in this case is a bit weird to me so would love to track down why. – Rob Segal Dec 09 '14 at 22:16

0 Answers0