Anybody knows what this doesn't work (Static member min cannot be used on instance of Type CGFloat. in the extension.
extension CGFloat {
mutating func normalize() {
self = min(max(CGFloat(0), self), CGFloat(1))
}
}
while this works
let f: CGFloat = CGFloat(0.4)
let maxValue = max(f, 1)
You can get this to work by specifying Swift.min and Swift.max as such:
extension CGFloat {
mutating func normalize() {
self = Swift.min( Swift.max(CGFloat(0), self), CGFloat(1))
}
}
when using just min and max it is unsure if you mean CGFloat.min or Swift.min
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.