Swift implements the weather forecast app Weather-forecast app using Swift

Source: Internet
Author: User

Recently the landlord in Swift self-study pain and happy, this simplest weather forecast function encountered a lot of small pits, vomiting blood record code.

/Viewcontroller.swift//WeatherCreated by Angela on 14/11/6.//Copyright (c) 2014 Angela. All rights reserved.//ImportUIKitclassViewcontroller:uiviewcontroller {@IBOutlet var tv:uitextview? @IBAction func btnpressed (sender:anyobject) {println ("Button Clicked") Loadweather ()} override func Viewdidload () {super.viewdidload ()Do any additional setup after loading the view typically froma nib. Loadweather ()} override func didreceivememorywarning () {super.didreceivememorywarning ()//Dispose of any resources the can be recreated. } func Loadweather () {var URL= Nsurl (string:"http://www.weather.com.cn/data/sk/101010100.html") println ("\ (URL)") var data=NSData (contentsofurl:url!) println ("\ (data)") var json:anyobject? =nsjsonserialization.jsonobjectwithdata (data! options:NSJSONReadingOptions.AllowFragments Error:nil) var W eatherinfo:anyobject! = JSON?. Objectforkey ("Weatherinfo") var city:anyobject! = Weatherinfo?. Objectforkey (" City") var temp:anyobject! = Weatherinfo?. Objectforkey ("Temp") var wind:anyobject! = Weatherinfo?. Objectforkey ("WD") var ws:anyobject! = Weatherinfo?. Objectforkey ("WS") TV?. Text="cities: \ (city) \ n temp: \ (temp) \ n: \ (wind) \ n \ Wind: \ (WS)"    }}

Swift implements the weather forecast app Weather-forecast app using Swift

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.