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 Simple Data Structures Bootstrapping the UI

Error: not convertible to "StringLiteralConvertible"

My stormy app didn't work as what I expected: (Instead of showing me the temperature "80" from the library, it shows me the default value "90º" which I typed in manually), so I delete the if let statement and just use the let statement to test it out. The code looks like this:

let plistPath = NSBundle.mainBundle().pathForResource("CurrentWeather", ofType: "plist") let weatherDictionary = NSDictionary(contentsOfFile: "plistPath") let currentWeatherDictionary = weatherDictionary["currently"] as? [String: AnyObject]

When I do so, there's an compiler error showing me that the following code:

let currentWeatherDictionary = weatherDictionary["currently"] as? [String: AnyObject]

cannot be executed because [String: AnyObject] is not convertible to StringLiteralConvertible.

I cannot figure out the problem. Can you help me?

let plistPath = NSBundle.mainBundle().pathForResource("CurrentWeather", ofType: "plist")
let weatherDictionary = NSDictionary(contentsOfFile: "plistPath")
et currentWeatherDictionary = weatherDictionary["currently"] as? [String: AnyObject] // This is where the error appears.
```html

4 Answers

Problem solved! So first I accidentally conjure up a pair of quotation marks around the variable plistPath. And Second, there's actually some very subtle differences when I get rid of the if let statement. Here are the codes that finally work around my problem (without if let statement)

let plistPath = NSBundle.mainBundle().pathForResource("CurrentWeather", ofType: "plist")
 let weatherDictionary = NSDictionary(contentsOfFile: plistPath!)
 let currentWeatherDictionary = weatherDictionary!["currently"] as? [String: AnyObject]

It seems that I have to unwrap the variable plistPath and weatherDictionary first to get the same result when using optional binding by if let statement. Great lesson for me!

even after doing it, I'm getting runtime error in

@IBOutlet weak var currentTemperatureLabel: UILabel?

I tried ! also like below

@IBOutlet weak var currentTemperatureLabel: UILabel!

please help

Can you paste your code here? and the error message?

@IBOutlet weak var currentTemperatureLabel: UILabel!

override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.

     let plistPath = NSBundle.mainBundle().pathForResource("CurrentWeather", ofType: "plist")
    let weatherDictionary = NSDictionary(contentsOfFile: plistPath!)
    let currentWeatherDictionary = weatherDictionary!["currently"] as? [String: AnyObject]

       let currentWeather = CurrentWeather(weatherDictionary: currentWeatherDictionary!)

        currentTemperatureLabel!.text = "\(currentWeather.temperature)"

}

Initially I typed exactly whats in the video, I got Run Time Error, so I changed the code as said in this thread, even for this I'm getting Run Time Error.

(lldb)

aDecoder NSCoder 0x00007f8ed4843e00 0x00007f8ed4843e00 self Stormy.ViewController 0x00007f8ed2f3de60 0x00007f8ed2f3de60

I'm getting Thread 1 : breakpoint 1.5 on @IBOutlet weak var currentTemperatureLabel: UILabel!

when I tried it from the start following the video again, I didn't get any error. everything worked. thanks for the help