Giter Site home page Giter Site logo

what-s-the-weather-ios-app's Introduction

#Weather App For iOS This app isn't going to the App Store because it doesn't use an API to retrieve the data from the source, it actually just reads the source code of the website and only takes the information that I need.

##Screen shots: alt tag alt tag alt tag alt tag

##Source code:

//  ViewController.swift
//  What's The Weather
//
//  Created by Divine Davis on 8/31/15.
//  Copyright (c) 2015 Divine's Ideas. All rights reserved.
//

import UIKit
import Foundation

class ViewController: UIViewController {

    //They user types in the city they want to recieve the weather from
    @IBOutlet weak var city: UITextField!
    
    //The label that is being updated when the data finally reaches the phone
    @IBOutlet weak var message: UILabel!
    
    //The progress bar
    @IBOutlet weak var downloadProgress: UIProgressView!
    
    //My 'What's the weather?' button
    @IBAction func buttonPressed(sender: AnyObject) {
        
        //When you touch the button, the keyboard goes away
        self.view.endEditing(true)
        
        //setting the urlString to the address of the website, it will add the city that you type into the city text field
        var urlString = "http://www.weather-forecast.com/locations/" + city.text.stringByReplacingOccurrencesOfString(" ",              withString: "") + "/forecasts/latest"
        
        //Setting the url to the urlString
        var url = NSURL(string: urlString)
        
        let task = NSURLSession.sharedSession().dataTaskWithURL(url!){(data, response, error) in
            
            var urlContent = NSString(data: data, encoding: NSUTF8StringEncoding)
            
            if (urlContent!.containsString("<span class=\"phrase\">")){
                
                var contentArray  = urlContent!.componentsSeparatedByString("<span class=\"phrase\">")
                var newContentArray = contentArray[1].componentsSeparatedByString("</span>")
                
                //Make this the main part of the code I want to run first
                dispatch_async(dispatch_get_main_queue()) {
            
                //Changing the text color to white
                self.message.textColor = UIColor .whiteColor()
                self.message.text = (newContentArray[0].stringByReplacingOccurrencesOfString("&deg;", withString: "º") as?                      String)
                
                }
            } else {
                
                //Stop doing anything else and complete this code also
                dispatch_async(dispatch_get_main_queue()) {
                
                //Changing the text color to red
                self.message.textColor = UIColor .redColor()
                
                //Error message
                self.message.text = "The weather was not able to be retrieved"
                }
            }
        }
        task.resume()
    }

what-s-the-weather-ios-app's People

Contributors

divinedavis avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.