Consider the following code:

let op1: Int = 1

let op2: UInt = 2

let op3: Double = 3.34

var result = op1 + op2 + op3

Where is the error and why? How can it be fixed?



Consider the following code: let op1: Int = 1 let op2: UInt = 2 let op3: Double = 3.34 v..

Answer / iosraj

Swift doesn’t define any implicit cast between data types, even if they are conceptually almost identical (like UInt and Int).

To fix the error, rather than casting, an explicit conversion is required. In the sample code, all expression operands must be converted to a common same type, which in this case is Double:

var result = Double(op1) + Double(op2) + op3

Is This Answer Correct ?    4 Yes 0 No

Post New Answer

More Apple iOS Swift Interview Questions

What is swift module?

0 Answers  


What is observer in swift?

0 Answers  


Mention what is the difference between Swift and ‘Objective-C’ language?

0 Answers  


What is nsmutablearray in swift?

0 Answers  


Explain grand central dispatch (gdc).

0 Answers  






What are functions in swift?

0 Answers  


What are the different ways to pass data in swift?

0 Answers  


In swift, what type of object are basic data types?

0 Answers  


What is the difference between swift and ‘objective-c’ language?

0 Answers  


Why do we use swift?

0 Answers  


What is lazy in swift?

0 Answers  


What is property observer in swift?

0 Answers  


Categories