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![](https://ecs-static.teamtreehouse.com/assets/views/marketing/shared/community-banner-white-47072046c51352fe6a69f5e691ff5700b28bb11d45197d7bdf066d9ea3f72d0c.webp)
![Pablo Lahoz](https://secure.gravatar.com/avatar/95d496ec55b7a7a47286fe9cbaa787e8?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Pablo Lahoz
6,337 PointsUILabels not retrieving plist data
So I have compared the code with Pasan's in the download section and checked out similar questions yet can't figure out where i'm going wrong. The UILabels will only show the numbers I put in the attributes inspector.
heres my code: import UIKit
class ViewController: UIViewController {
@IBOutlet weak var currentTemperatureLabel: UILabel?
@IBOutlet weak var currentHumidityLabel: UILabel?
@IBOutlet weak var currentPrecipitationLabel: UILabel?
override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
if 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)º"
currentHumidityLabel?.text = "\(currentWeather.humidity)%"
currentPrecipitationLabel?.text = "\(currentWeather.precipProbability)%"
}
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
}
//And CurrentWeather.swift
import Foundation
struct CurrentWeather {
let temperature: Int
let humidity: Int
let precipProbability: Int
let summary: String
init(weatherDictionary: [String: AnyObject ]) {
temperature = weatherDictionary["temperature"] as! Int
humidity = weatherDictionary["humidity"] as! Int
precipProbability = weatherDictionary["precipProbability"] as! Int
summary = weatherDictionary["summary"] as! String
}
}
1 Answer
![Pablo Lahoz](https://secure.gravatar.com/avatar/95d496ec55b7a7a47286fe9cbaa787e8?s=96&d=https%3A%2F%2Fecs-static.teamtreehouse.com%2Fassets%2Fcontent%2Fdefault_avatar-445fbbabfc8dc9188fb5967fe43322ee0c3e0dd1e10f378bf8343784af5a13eb.webp&r=pg)
Pablo Lahoz
6,337 PointsYes, sorry I should have posted this before. The code is fine I just had to check some box in the attributes inspector of the main storyboard. Thank you for replying though.
Tal Zion
6,234 PointsTal Zion
6,234 PointsI used your code it works. Check the plist file to see if the values match