0

If I so much as open a xib or storyboard in Xcode 8 GM and choose a device/orientation to "View as" parts of my code involving custom UIView classes start crashing hard when I build and run my app. This applies to any edit I make to a xib/storyboard as well.

Here's my call stack for my custom UIView that's crashing after setting my "View as" in my main storyboard (also happens every time in xibs):

initWithCoder
layoutIfNeeded (called after I call setNeedsLayout)


Terminating app due to uncaught exception 'CALayerInvalidGeometry', reason: 'CALayer position contains NaN: [97 nan]'

First throw call stack: (0x182adedb0 0x182143f80 0x182adecf8 0x1855b95d4 0x1855b9530 0x1012d2474 0x1855b94c8 0x18822d05c 0x18822ced8 0x18822d008 0x187c30618 0x187c421cc 0x1885a5ed8 0x187c83a48 0x187c341e4 0x1855c298c 0x1855bd5c8 0x187c4b0a4 0x1001c2b0c 0x1001c19ac 0x10010cecc 0x1881106b0 0x188234438 0x1882345b0 0x188234180 0x187f420e4 0x188234438 0x188234180 0x1835957b0 0x188234438 0x1882345b0 0x188234180 0x1884d44c0 0x188234438 0x188234180 0x1835957b0 0x1881106b0 0x188234438 0x188234180 0x188110354 0x188234438 0x1882345b0 0x188234180 0x18810f688 0x187fb1230 0x187d76118 0x187c388ec 0x187c38844 0x187c3f59c 0x187c3ca88 0x187cb2fa4 0x187ede3ac 0x187ee25f0 0x187edf764 0x18447f7ac 0x18447f618 0x18447f9c8 0x182a9509c 0x182a94b30 0x182a92830 0x1829bcc50 0x187ca794c 0x187ca2088 0x10027d938 0x18255a8b8)


Any insight into this issue is much appreciated. I assume things haven't been "laid out" yet, and maybe triggering a layout in initWithCoder is poor form, but it's never been an issue before and it's only an issue with xibs/storyboards in Xcode 8 GM.

Sangram Shivankar
  • 3,535
  • 3
  • 26
  • 38
Rocksaurus
  • 53
  • 5

1 Answers1

0

For the sake of anyone stumbling upon this in the future from Google I'm pretty sure the issue can be explained by these two posts:

XCode8 initWithCoder frame Size

Proper practice for subclassing UIView?

In short: Xcode 8 changes xibs such that they don't report a (bogus) frame to UIView's initWithCoder, causing my crashes. As inquired/suspected it is poor form to do any layout in initWithCoder. Xcode 8 is simply forcibly correcting my error.

Community
  • 1
  • 1
Rocksaurus
  • 53
  • 5