Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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?

Answer Posted / 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       View All Answers


Please Help Members By Posting Answers For Below Questions

What do you mean by the term “defer”?

795


What is retain in swift?

824


What is $0 in swift?

812


What is difference between xcode and swift?

908


What is a static variable swift?

851


What is a swift protocol?

885


Do loops swift?

753


Is swift similar to python?

874


How can you make a property optional in swift?

800


How do I create a swift file in xcode?

864


How you define variables in swift?

901


What is difference between single and double, in swift?

805


Can you explain any three-shift pattern matching techniques?

798


What is the significance of “?” In swift?

861


Is swift object oriented programming?

851