I am developing a collection view, In some cases, to avoid runtime exceptions, I need to return my collection view size to a least minimum size. So that the view takes a minimum space which is too small to view.
Here is the code snippet I tried but I am getting the error:
Ambiguous use of 'leastNonzeroMagnitude'
func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, estimatedItemSize section: Int) -> CGSize {
return .init(width: .leastNormalMagnitude, height: .leastNonzeroMagnitude)
}
But if I return .init(width: 0.0, height: .leastNonzeroMagnitude) there is no error.
I found a similar question What is the difference between leastNormalMagnitude, leastNonZeroMagnitude and automaticDimention in UITableview. But there is no answer to this question.
According to the documentation about leastNonzeroMagnitude
So simply, leastNonzeroMagnitude <= leastNormalMagnitude and in this scenario, it will make no difference.
Both
leastNonzeroMagnitudeandleastNormalMagnitudehave static variables that return a Double | CGFloat | Float. The CGSize initial function cannot determine which value it may be from the above types. That's why the error appears. You can click the error and check theQuick Helpmenu on the right hand side of Xcode's navigation.To fix it, you just need to make
leastNormalMagnitudeandleastNonzeroMagnitudeconform to the correct type before returningCGSize