Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

Nitro187

macrumors newbie
Original poster
Oct 28, 2021
2
0
I have some code that's attempting to create some PDF's in the background, and it worked great until I upgraded to xCode 13. Now it seems as though it's having issues initializing some code, and I'm wondering if anyone can help me out.

NewCustomPageViewController *pvc = (NewCustomPageViewController*)self.parentViewController.parentViewController; //loads object fine

for (UIViewController *vc in pvc.pages) { //loads object fine
UIView *mainView = [[[vc.view.subviews objectAtIndex:0] subviews] objectAtIndex:0]; //<- It's crashing here
}


That's the code that's throwing the error: Thread 23: EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)

I don't know what to do, and it doesn't even seem to be getting to the loaded UIViewController that it's attempting (The vc.view.subviews object) as from within xCode, it's showing that as loaded, but it's just crashing.

Is there something else I should be doing? This has worked beautifully before in the old xCode (I believe xCode 9 or 11? I forget)

Thanks in advance!!
 
First thing to do is inspect the elements that could be nil or empty.

For instance is vc.view.subviews nil? If not, what is the count? If your getting a view back from that then do the same for the returned view.

I’d consider placing NSLog statements where those subviews get setup and right before this for loop. That May hint that the subviews are no longer getting setup earlier than the call that gets you here.
 
First thing to do is inspect the elements that could be nil or empty.

For instance is vc.view.subviews nil? If not, what is the count? If your getting a view back from that then do the same ref for the returned view.

I’d consider placing NSLog statements where those subviews get setup and right before this for loop. That May hind that the subviews are no longer getting setup earlier than the call that gets you here.
Thanks for responding xStep.

I've tried NSLog'ing vc, and it shows the element just fine.... I couldn't find "view", so obviously I couldn't find "subviews" either. Is there a reason why this would work in previous versions of xCode, and not this one? Syntax change or something that would not allow subviews to load?

NSLog(@"%@", vc); //<- this works fine.... Element shows up.
NSLog(@"%@", vc.view); <- this crashes it....

Where should I start to look at getting this working?

Thanks!
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.