Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialFotis Diamantopoulos
1,794 PointsI get an error
When defining the constant areaInMeters I get the error "Type 'int' does not conform to protocol 'FloatLiteralConvertible". The console output is "Playground execution failed: <EXPR>:18:27: error: type 'Int' does not conform to protocol 'FloatLiteralConvertible' let areaInMeters = area / 10.764"
7 Answers
Andres Oliva
7,810 PointsTry writing
let (or var) area: Double = xxx
or
let areaInMeters = Double(area)/10.764
Your problem is that "area" is being type inferred as Int. Anyway, you shouldn't be getting an error, it should just return an Int value. Would it be possible for you to share your code? :)
Hope that helps!
Gloria Dwomoh
13,116 PointsHi Fotios, I am not sure what your code contains but it says you are mixing up integers with float. Is the variable area an integer while 10.746 you are trying to divide it with a float? Try checking out the type of the variables you are working on.
Goran Jakovljevic
920 PointsIt seems that in video, he was able to mix integers and floats, but in current version of xCode, you cant do that, so in order to fix this bug, you just need to define first constants as double and it will work.
Robert Mehew
2,427 PointsThis helped me get past this step. Assigning the first two as double.
Maura Pfeifer
172 PointsI get the same error at Fotios. The code I was entering was exactly the same as in the video. When I set each of the variables to be Double, it works. But without doing that I get the same error. I wonder if it's a different version of Xcode?
Mike Cho
570 PointsYes, same issue here. I agree. It seems to be related to the version of Xcode we are using. I am using 6.1.
Drew Jolesch
2,076 PointsI just changed all my constants to : Double and that fixed the issue. Running version 6.1 so appears to be a new error being called out that wasn't in 6.0.
Jack Bonner
1,093 PointsHey, It looks like he just had a different version of xCode because I get the same error. While doing Treehouse, Im also getting my Bachelors in Mobile Development. What we learned, was to always put the TYPE with your Variable or Constant. It's good practice and reduces errors like this.
Fotis Diamantopoulos
1,794 PointsFotis Diamantopoulos
1,794 PointsHi,
i get why this is happening but in the "Swift Basics Course" at the "Binary Operators" video tutorial it seems to work. Actually the division " area / 10.764 " gives a result of 12 even though area is an int. When I try that in Xcode 6.1 I get the error I mentioned. My code is:
// Playground - noun: a place where people can play
import UIKit
let height = 12 //feet let width = 10 // feet
let area = height * width //sq. feet
let areaInMeters = area / 10.764 //sq. meters