Created
April 23, 2015 19:33
-
-
Save mlassoff/389ea54f921c530aaa84 to your computer and use it in GitHub Desktop.
Weather App from LearnToProgram Webinar 4/2015
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// ViewController.swift | |
// WeatherWebinar | |
// | |
// Created by Mark Lassoff on 4/23/15. | |
// Copyright (c) 2015 Mark Lassoff. All rights reserved. | |
// | |
import UIKit | |
class ViewController: UIViewController { | |
@IBOutlet weak var txtZip: UITextField! | |
@IBOutlet weak var imgWeather: UIImageView! | |
@IBOutlet weak var txtConditions: UILabel! | |
@IBAction func getWeatherConditions() { | |
var url:String = "http://api.wunderground.com/api/df813c985b3d8af6/conditions/q/" | |
url += txtZip.text | |
url += ".json" | |
var request: NSMutableURLRequest = NSMutableURLRequest() | |
request.URL = NSURL(string: url) | |
request.HTTPMethod = "GET" | |
NSURLConnection.sendAsynchronousRequest(request, queue: NSOperationQueue(), completionHandler:{ (response:NSURLResponse!, data: NSData!, error: NSError!) -> Void in | |
var error: AutoreleasingUnsafeMutablePointer<NSError?> = nil | |
let json = JSON(data:data) | |
var output:String = "" | |
if let city = json["current_observation"]["display_location"]["full"].string { | |
output = "Location: " + city | |
} | |
if let temp = json["current_observation"]["temp_f"].string{ | |
output += "\nTemperature: " + temp | |
} | |
if let wind = json["current_observation"]["wind_string"].string{ | |
output += "\n" + wind | |
} | |
println(output) | |
}) | |
} | |
override func viewDidLoad() { | |
super.viewDidLoad() | |
// Do any additional setup after loading the view, typically from a nib. | |
} | |
override func didReceiveMemoryWarning() { | |
super.didReceiveMemoryWarning() | |
// Dispose of any resources that can be recreated. | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment