gpt4 book ai didi

ios - Swift - 表达式太复杂,无法在合理的时间内解决;考虑将表达式分解为不同的子表达式

转载 作者:行者123 更新时间:2023-11-28 07:06:52 27 4
gpt4 key购买 nike

当我尝试返回值时收到此错误消息。

/Users/MNurdin/Documents/iOS/xxxxx/RangeSlider.swift:76:109: Expression was too complex to be solved in reasonable time; consider breaking up the expression into distinct sub-expressions

我的代码

var minimumValue: Float = 0.0
var maximumValue: Float = 1.0
var minimumRange: Float = 0.0
var selectedMinimumValue: Float = 0.2
var selectedMaximumValue: Float = 0.8

var distanceFromCenter: Float = 0.0

var _padding: Float = 20

/**/

func xForValue(value: Float){
return (self.frame.size.width-(_padding*2))*((value - minimumValue) / (maximumValue - minimumValue))+_padding; //error here
}

func valueForX(x: Float){
return minimumValue + (x-_padding) / (self.frame.size.width-(_padding*2)) * (maximumValue - minimumValue); //error here
}

我该如何解决?

最佳答案

为函数添加了返回类型并将 CGFloat 转换为 Float

func xForValue(value: Float) -> Float {
return (Float(self.frame.size.width) - (_padding * 2)) * ((value - minimumValue) / (maximumValue - minimumValue)) + _padding;
}

func valueForX(x: Float) -> Float {
return minimumValue + (x - _padding) / (Float(self.frame.size.width) - (_padding * 2)) * (maximumValue - minimumValue);
}

关于ios - Swift - 表达式太复杂,无法在合理的时间内解决;考虑将表达式分解为不同的子表达式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30208871/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com