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

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


I had the same error when I tried to multiply view.frame.height by a Double. If you are doing any math on screenBounds properties, make sure the types match.


My problem was that I was trying to perform an operation between a CGFloat variable and Double variable.

Fix: Convert the Double variable to CGFloat. Check your variable types.

I hope it helps! :)


I got here looking for an answer to what was causing the error "Expression type '@lvalue CGRect' is ambiguous without more context", and while nothing here answered this for me I did find the solution to the problem so I'll leave it here for anyone else who stumbles on this question via Google. When creating your CGRect make sure to explicitly cast any ambiguous values to CGFloats (e.g. var width = CGFloat(100)) instead of relying on the compiler to infer the correct type/cast for you.