Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

"API error: (null) returned 0 width, assuming UIViewNoIntrinsicMetric" in Xcode 9 beta

I'm working on several projects and it happens the same error.

I still can't figure out what's causing it. Is it the problem with my code or Xcode 9 beta?

MyApp[22724:4000717] API error: (null) returned 0 width, assuming UIViewNoIntrinsicMetric

like image 253
IceApinan Avatar asked Jul 22 '17 16:07

IceApinan


1 Answers

@rmaddy correctly linked to another SO answer however there are other possibilities related to auto layout practices.

The message could also be related to auto layout implementations and unique constraints defined in your project. It seems that this message normally does not appear when using a real device.

UIKit framework -> UIView API Global Variable UIViewNoIntrinsicMetric

UIViewNoIntrinsicMetric The absence of an intrinsic metric for a given numeric view property.

UIView Implementation Practices

Every UIView subclass should implement the intrinsicContentSize and return the size that it thinks is suitable for it. For example:

  • If you know the UIView's width you use return CGSizeMake(200, 50).
  • If you don't know how wide the view is you would use UIViewNoIntrinsicMetric instead of the width. return CGSizeMake(UIViewNoIntrinsicMetric, 50)

UIView base implementation of updateConstraints will call the intrinsicContentSize and it will use the content size returned from it to add constraints to the UIView.

UIView API Property intrinsicContentSize

intrinsicContentSize The natural size for the receiving view, considering only properties of the view itself.

Custom views typically have content that they display of which the layout system is unaware. Setting this property allows a custom view to communicate to the layout system what size it would like to be based on its content. This intrinsic size must be independent of the content frame, because there’s no way to dynamically communicate a changed width to the layout system based on a changed height, for example. If a custom view has no intrinsic size for a given dimension, it can use UIViewNoIntrinsicMetricfor that dimension.

Conclusion

Xcode error:

returned 0 width, assuming UIViewNoIntrinsicMetric

Therefore we can get an idea that Xcode is assuming a UIViewNoIntrinsicMetric size since a width size of 0 was returned by some UIView in your project.

If you are still getting the message when deploying on a real device then I'd pay extra attention to your layout constraints.

like image 155
Edison Avatar answered Nov 15 '22 08:11

Edison