HuberyYang
HuberyYang

Reputation: 11

Cannot invoke 'CGRect.Type.init' with an argument list of type '(x: Int, y: Int, width: Float, height: Float)'

I'm learning swift,but a mistake was encountered when initializing collectionview,the error message is 'Cannot invoke 'CGRect.Type.init' with an argument list of type '(x: Int, y: Int, width: Float, height: Float)''.And,here is my screenshot:

Thank you for any help!

Upvotes: 0

Views: 1774

Answers (2)

ced
ced

Reputation: 96

CGRect.init has three different versions, for the three types of arguments it accepts - Int, Double, and CGFloat. Whatever values you're passing into x, y, width, and height must be the same type. To fix this you might try casting your values to Double by wrapping them in Double().


Regarding your comment, there's no version of CGRect.init() that takes Float parameters. Cast your Floats to Double and it should work.

Upvotes: 1

Sagar Chauhan
Sagar Chauhan

Reputation: 5823

You have passing arguments data with the different type. Here you have set x and y position with Int Type and width & height with Float data type. these all four type must be same.

Upvotes: 0

Related Questions