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 trial

iOS Build a Weather App with Swift (Retired) Data Modeling With Structures Cleaning Up Our Date

Tal Zion
Tal Zion
6,234 Points

ERROR: 'Double' is not convertible to UInt8 (in humidity key)

Hi,

I get an error when launching my weather app. Checked all variables within the struct and all is correct, including copying the ones from the JSON.

Thanks for your help

9 Answers

Tal,

You have

humidity - currentWeather["humidity"] as Double

It should read

humidity = currentWeather["humidity"] as Double

This should fix this issue.

Hi Tal,

Can you post your code for us to check out?

Tal Zion
Tal Zion
6,234 Points

Hi Aaron,

This is my code, thanks!

var currentTime: String?
var temperature: Int
var humidity: Double
var precipProbability: Double
var summery: String
var icon: UIImage?

init(weatherDictionary: NSDictionary) {
    let currentWeather = weatherDictionary["currently"] as NSDictionary

    temperature = currentWeather["temperature"] as Int
    humidity - currentWeather["humidity"] as Double
    precipProbability = currentWeather["precipProbability"] as Double
    summery = currentWeather["summary"] as String

      let currentTimeIntValue = currentWeather["time"] as Int
    currentTime = dateStringFromUnixtime(currentTimeIntValue)

    let iconString = currentWeather["icon"] as String
    icon = weatherIconFromString(iconString)
}

func dateStringFromUnixtime(unixTime: Int) -> String {
    let timeInSeconds = NSTimeInterval(unixTime)
    let weatherDate = NSDate(timeIntervalSince1970: timeInSeconds)

    let dateFormatter = NSDateFormatter()
    dateFormatter.timeStyle = .ShortStyle

    return dateFormatter.stringFromDate(weatherDate)
}

func weatherIconFromString(stringIcon: String) -> UIImage {
    var imageName: String

    switch stringIcon {
    case "clear-day":
        imageName = "Sun-thin"
    case "clear-night":
        imageName = "Moon-thin"
    case "rain":
        imageName = "Rain"
    case "snow":
        imageName = "Snow"
    case "sleet":
        imageName = "Hall"
    case "wind":
        imageName = "Tornado-thin"
    case "fog":
        imageName = "Sunrise"
    case "cloudy":
        imageName = "Cloud"
    case "partly-cloudy-day":
        imageName = "PartlySunny"
    case "partly-cloudy-night":
        imageName = "PartlyMoon"
    default:
        imageName = "default"
    }

    var iconImage = UIImage(named: imageName)
    return iconImage!
}
Tal Zion
Tal Zion
6,234 Points

Thanks Aaron, missed it.

Can you help with another issue? I am using XCODE 6.1 and it doesn't auto complete Classes and Libraries, only like variables etc. This is frustrating as it takes my 5 times longer to code. Checked the preferences and all Auto Complete check boxes are ticked. Further, I made sure all documentation are downloaded. I really need you help if possible, so far, what I heard that this may be a bug with Xcode 6.1.

If I delete Xcode and re-install, would it fits it?

Thanks again.

Yeah, I have had the same issue in the past. What I did was re-install Xcode. So far things are working fine.

Tal Zion
Tal Zion
6,234 Points

Wow, thanks! To uninstall, should I just drag to trash or do I need to completely uninstall from Terminal or something?

Dragging it to the trashcan should get the job done. I use App Zapper myself.

http://www.appzapper.com

Tal Zion
Tal Zion
6,234 Points

Hi Aaron,

Still doesn't work. For example, when I type N - it should start recommending all the Classes that starts with N. Unfortunately, it only recommend like 6 options which are:

nil NilLiteralConvertible n numeric... n numrc...

That's it. I also noticed, that when I start typing an Object variable I created, so the recommendation should say for example

L Type VarName like I saw in the lectures. For me, it shows

L <<error type>> VarName

I think this is where the problem, I don't know where to find it.

Thanks again, and hope to hear from you. Tal

Tal Zion
Tal Zion
6,234 Points

Hi Aaron,

Still doesn't work. For example, when I type N - it should start recommending all the Classes that starts with N. Unfortunately, it only recommend like 6 options which are:

nil NilLiteralConvertible n numeric... n numrc...

That's it. I also noticed, that when I start typing an Object variable I created, so the recommendation should say for example

L Type VarName like I saw in the lectures. For me, it shows

L <<error type>> VarName

I think this is where the problem, I don't know where to find it.

Thanks again, and hope to hear from you. Tal

I'm running Version 6.1 (6A1052d) are you running the same?

Tal Zion
Tal Zion
6,234 Points

Yes, I am running Version 6.1 (6A1052d) too.

Open your project in xCode and run Product -> Clean (maybe this will help)

Tal Zion
Tal Zion
6,234 Points

Tried it and no luck :. Its weird as all works fine and the App is working. Also, it seems there is a chunk of Classes and Objects that are missing from the Auto Complete as it does recommend some.

I took some Screen Shots for you to see how the auto complete works and what it represents.

https://www.dropbox.com/sh/kuanh7u48f6i1do/AABsu341u4rHSx6LXBB4oXmla?dl=0

Thanks

Beats me man..