How to Solve Error Swift 4 Expression type ‘@value CGRect’ is ambiguous without more context

Swift 4 Expression type’@value CGRect’ is ambiguous without more context

For example, there is now a class:


class ImageListView: UIView {
    var moment: Moment!
    var tapSmallView: ((_ iamgeView: UIImageView) -> Void)?
    var imagesArray: [UIImageView]!
    //ImagePreviewView is another custom class, which has a scrollView
    var imagesPreview: ImagePreviwView!
    
    
    func setMoment(_ moment: Moment) {
        self.moment = moment
        let count = moment.ImageCount
        imagesPreview.scrollView.contentSize = CGSize(width: imagesPreview.frame.width*count, height: imagesPreview.frame.height)
    }
}

In this case, setting the contentSize of the scrollView will report an error, because count is of type Int. If we do any mathematical operations on screenBounds, please make sure to check the type matches.

You must change the type:

imagesPreview.scrollView.contentSize = CGSize(width: imagesPreview.frame.width*CGFloat(count), height: imagesPreview.frame.height)


Read More:

Leave a Reply

Your email address will not be published. Required fields are marked *