0

I upgraded my swift 4.2 application to Swift 5 and I get this error. Does anyone know how to fix?

File using: GMStepper.swift

Error: Cannot convert value of type 'String' to expected argument type 'DefaultStringInterpolation'

if self.showIntegerIfDoubleIsInteger && floor(self.value) == self.value {
            label.text = String(stringInterpolation: "\(Int(self.value))\(self.suffixString)")
        } else {
            label.text = String(stringInterpolation: "\(Int(self.value))\(self.suffixString)")
        }

2 Answers 2

1

You should do like this :

if self.showIntegerIfDoubleIsInteger && floor(self.value) == self.value {
        let intValue =  Int(self.value)
        label.text = String(stringInterpolation: "\(intValue)\(self.suffixString)")
    } else {
        let intValue =  Int(self.value)
        label.text = String(stringInterpolation: "\(intValue))\(self.suffixString)")
    }
Sign up to request clarification or add additional context in comments.

Comments

0

You should not call String.init(stringInterpolation:) directly.

init(stringInterpolation:)

Discussion

Do not call this initializer directly. It is used by the compiler when you create a string using string interpolation. Instead, use string interpolation to create a new string by including values, literals, variables, or expressions enclosed in parentheses, prefixed by a backslash (\(…)).

Why don't you simply write your code as:

    if self.showIntegerIfDoubleIsInteger && floor(self.value) == self.value {
        label.text = "\(Int(self.value))\(self.suffixString)"
    } else {
        label.text = "\(Int(self.value))\(self.suffixString)"
    }

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.