I was looking to the getRed
of UIColor and I noticed we should be working with inout parameters to make it work! But I do not know why Xcode does not help me out to fix my mistake when I am not using the &
before parameter! Instead of getting related help from Xcode I do get this help for this mistake:
Cannot convert value of type 'CGFloat' to expected argument type 'UnsafeMutablePointer?'
var r: CGFloat = 0
var g: CGFloat = 0
var b: CGFloat = 0
var a: CGFloat = 0
UIColor.blue.getRed(r, green: &g, blue: &b, alpha: &a)
Well that I know what is the issue, but the complain of Xcode does not help me out to know that I forgot &
.
For example I made a simple test function, in case I do mistake Xcode help me like this:
Passing value of type 'CGFloat' to an inout parameter requires explicit '&'
func test(value: inout CGFloat) { value += 1.0 }
var r: CGFloat = 0
test(value: r)
So why I do not get same message for the same mistake?
PS: If we could use the getRed
without inout parameters, how could be done in that case? because with getting such help from Xcode I am think the issue is not about inout and could be get those value in other way.
Xcode: Version 12.5.1 (12E507)