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 trialFlotteur Zygon
3,995 PointsUILabels are showing the placeholder text instead of plist data
When I run the simulation, the UILabels are showing 90º for temperature, 88% for humidity and 88% for rain (the placeholder text used). I have compared my xcode files with the one included in the download section of the video and didn't find where I messed it. I presume the problem reside in the ViewController.swift file but am not sure.
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.
}
}
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
let humidityFloat = weatherDictionary["humidity"] as! Double
humidity = Int(humidityFloat * 100)
let precipFloat = weatherDictionary["precipProbability"] as! Double
precipProbability = Int(precipFloat * 100)
summary = weatherDictionary["summary"] as! String
}
}
Kevin Gonzales
4,638 PointsI think I know where the problem is. I am thinking we do not meet our requirements in our if let statement and therefore our code updating the placeholders doesn't execute. If i fix it I will let you know.
Kevin Gonzales
4,638 PointsSo I solved my problem and I think I found yours. When initializing plistpath the name of the file you passed was currentWeather, but the plist name has a capital C. Try capitalizing the c in your currentWeather (its the string following path for resource). I think that should work.
Flotteur Zygon
3,995 PointsWow thanks! :)
Kevin Gonzales
4,638 Pointsno problem!
Toluwa Fayemi
926 PointsI seem to have my C's capitalized and my Target Membership boxes checked off...is there perhaps any other fixes to this issue?!?!!?
Ryan Nelson
2,369 PointsThis isn't working for me either!
1 Answer
Mark Weiser
2,093 PointsI also had this issue. After much trial and error I realized that I just needed to check the box where the app name is listed in the Target Membership of the Utilities sidebar. This can be found in the File Inspector part of the Utilities sidebar (right bar).
Kevin Gonzales
4,638 PointsKevin Gonzales
4,638 Pointssame problem here!