Giter VIP home page Giter VIP logo

clima's Introduction

Clima App

The entire process to create current application is as follows:

  1. Create a simple single view application for iOS
  2. Design the UI
  3. Close the application
  4. Install cocoapods.org unless you did in the past
  5. cd to your application workspace
  6. run pod setup --verbose
  7. run pod init
  8. open your Podfile with your editor
  9. Pods 8.1 uncomment the specification 8.2 add required pods 8.2.1 pod 'SwiftyJSON' 8.2.2 pod 'SVProgressHUD' 8.2.3 pod 'Alamofire' 8.3 save 8.4 run pod install
  10. open *.xcoprojectworks
  11. let WeatherViewController to inherit from CLLocationManagerDelegate
  12. define locationManger = CLLocationManager
  13. in viewDidLoad() 12.1. set locationManager to self 12.2. set locationManager.desiredAccuracy to your preference or requirement 12.3. set locationManager.requestWhenInUseAuthorization()
  14. open Info.plist 13.1. add Privacy - Location When In Use Description 13.2. add Privacy - Location Usage Discription 13.3. we use Open Weather Map via http add the following
  <key>NSAppTransportSecurity</key>
  <dict>
    <key>NSExceptionDomains</key>
    <dict>
      <key>openweathermap.org</key>
      <dict>
         <key>NSIncludesSubdomains</key>
         <true/>
         <key>NSTemporaryExceptionAllowsInsecureHTTPLoads</key>
         <true/>
      </dict>
    </dict>
  </dict>
  1. write function didUpdateLocations
  • check last location in locations variable
  • if it owns higher value than 0 then get 'longitude' and 'latitude' variable
  • stopUpdatingLocation() and set locationManager.delegate to nil
  1. write function didFailWithError
  • print error
  • inform user by updating cityLabel with 'Location's unavailable'
  1. call startUpdatingLocation function in viewDidLoad function
  2. create a params dictionary variable and save latitude, longitude and appid in it.
  3. cal getWeatherData and provide url and parameters for it
  4. import Alamofire and SwiftyJSON
  5. complete Alamofire.request(url, method: .get, parameters: parameters).responseJSON {}
  6. then check the if response.result is success or failure
  7. save the response.result.value in an unwraped variable as a JSON type
  8. create a class named WeatherDataModel and declare variables as the following list
let/var name type value
var temperature int 0
var condition int 0
var city String ""
var weatherIconName String ""
  1. also add a function named updateWeatherIcon which implements a switch statement to convert code to an icon.
  2. call the updateUIWithWeatherData function and set the available data.
  3. Navigating Data Between View Controllers. In ChangeCityViewController declare a protocol and define userEnteredANewCityName function that requires a string value. NOTE definition must be before the class definition.
  4. declare an optional delegate variable of the created protocol. NOTE by convention the name of this variable is delegate.
  5. in getWeatherPressed function, assign the text of text field to a variable and if it's not nil call the userEneteredANewCityName function by passing city name on delegate variable.
  6. dismiss the current view controller by calling self.dismiss(animated: true, completion: nil) function.
  7. in WeatherViewController, confirm to inherite ChangeCityDelegate.
  8. implement goToChangeCityViewControllerButtonPressed by calling performSegue(withIdentifie: "identifier's name", sender: self).
  9. implement change city view delegate method, define a dictionary variable and store "q" as a city name and app_id. Then call getWeatherData.
  10. override prepare function for segue and check if the segue.identifier is equal to segue's name then create segue.destination a viewcontroller variable as! ChangeCityViewController and then assign its delegate to self

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.