IOS

iOS - The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions(Rx 타입추론에러)

clamp 2023. 2. 23. 16:01

The compiler is unable to type-check this expression in reasonable time; try breaking up the expression into distinct sub-expressions

 

Rx를 공부하다가 발생한 에러.

 

combineLatest와 map을 사용하다가 발생했다.

타입을 추론하기 어려워 빌드할 수 없다는 내용

 

Observable.combineLatest([redSlider.rx.value, greenSlider.rx.value, blueSlider.rx.value])
            .map{ UIColor(red: CGFloat($0[0]) / 255, green: CGFloat($0[0]) / 255, blue: CGFloat($0[0]) / 255, alpha: 1.0)
            }
            .bind(to: colorView.rx.backgroundColor)
            .disposed(by: bag)

Observable.combineLatest([redSlider.rx.value, greenSlider.rx.value, blueSlider.rx.value])
            .map{ source -> UIColor in
              let red = CGFloat(source[0]) / 255
              let green = CGFloat(source[1]) / 255
              let blue = CGFloat(source[2]) / 255
                
                return UIColor(red: red, green: green, blue: blue, alpha: 1.0)
            }
            .bind(to: colorView.rx.backgroundColor)
            .disposed(by: bag)

로 하나하나 잘 쪼개고 리턴타입을 정확히 명시해주니 해결됐다.