Get current weather from openWeather APIs.

Overview

JCSWeatherKit

CI Status Version License Platform

JCSWeatherKit is a simple weather library for iOS. It can fetch weather data from OpenWeatherMap. More data sources will be supported and extensions will be supported in the future.

Example

To run the example project, clone the repo, and run pod install from the Example directory first.

Example png

Requirements

iOS 11.0+

Installation

JCSWeatherKit is available through CocoaPods. To install it, simply add the following line to your Podfile:

pod 'JCSWeatherKit'

Usage

There are a lot of unit tests in the file "JCSWeatherKitTests". You can refer to the usage method inside. Also, some code snippets are as followed.

OpenWeatherMap

Creating a weather session
#import <JCSWeatherKit/JCSWeatherKit.h>

    JCSOpenWeatherSource *src = [[JCSOpenWeatherSource alloc] initWithBaseURL:[NSURL URLWithString:@"http://api.openweathermap.org/data/2.5/weather"] appid:@"YOUR API KEY"];
    JCSWeatherSession *session = [[JCSWeatherSession alloc] initWithSource:src];
Getting weather by City ID
    JCSWeatherRequestInfo *requestInfo = [[JCSWeatherRequestInfo alloc] init];
    requestInfo.cityID = @"5128638";
    
    [self.session asyncGetWeather:requestInfo completion:^(JCSWeatherData * _Nullable data, NSError * _Nullable error) {
        if (data) {
            //handle data
        }else {
           //show error
        }
    }];
Getting weather by City Name
    JCSWeatherRequestInfo *requestInfo = [[JCSWeatherRequestInfo alloc] init];
    requestInfo.cityName = @"London";
    
    [self.session asyncGetWeather:requestInfo completion:^(JCSWeatherData * _Nullable data, NSError * _Nullable error) {
        if (data) {
            //handle data
        }else {
           //show error
        }
    }];
Getting weather by Zip Code
    JCSWeatherRequestInfo *requestInfo = [[JCSWeatherRequestInfo alloc] init];
    requestInfo.zipCode = @"94040,us";
    
    [self.session asyncGetWeather:requestInfo completion:^(JCSWeatherData * _Nullable data, NSError * _Nullable error) {
        if (data) {
            //handle data
        }else {
           //show error
        }
    }];
Getting weather by Coordinate
    JCSWeatherRequestInfo *requestInfo = [[JCSWeatherRequestInfo alloc] init];
    requestInfo.coordinate = CLLocationCoordinate2DMake(43.700111, -79.416298);
    
    [self.session asyncGetWeather:requestInfo completion:^(JCSWeatherData * _Nullable data, NSError * _Nullable error) {
        if (data) {
            //handle data
        }else {
           //show error
        }
    }];
Getting weather by user current location
    
    [self.session asyncGetWeather:nil completion:^(JCSWeatherData * _Nullable data, NSError * _Nullable error) {
        if (data) {
            //handle data
        }else {
           //show error
        }
    }];

Architecture

JCSWeatherKit is implemented as a layered architecture.

+-------------------------------------------------------------+
|                         JCSWeatherKit                        |
|        +----------------------------------------------------+
|        |                  JCSWeatherSession                           |
|    +--------------------------------------------------------+
|    | JCSOpenWeatherSource | JCSWeatherRequestInfo | JCSLocationService | 
+----+-----------------+-----------------+--------------------+
|       JCSWeatherData        |     JCSWeatherError    |
+----------------------+-----------------+

JCSWeatherSession

Provides asynchronous request of getting weather from OpenWeatherAPI. The input weather source needs to be set by the initial method or attribute.

Primary entry points: JCSWeatherSession.h,

JCSOpenWeatherSource

Provides configuration data, including APPID and base URL where JCSWeatherSession can get weather data from.

Primary entry point: JCSOpenWeatherSource.h

JCSWeatherRequestInfo

Used for passing parameters to OpenWeatherAPI, such as city id, city name, zip code, and so on.

In the category JCSWeatherRequestInfo+Private, splices URL through parameters. Primary entry point: JCSWeatherRequestInfo.h

JCSLocationService

Used for getting user location to fetch weather data.

Primary entry point: JCSLocationService.h

JCSWeatherData

A data container for all weather data. Also provides transforming JSON data to all the weather data.

Primary entry point: JCSWeatherData.h

JCSWeatherError

Defines errors types and passes control to a supplied function. It handles the following errors:

  • invalid weather source.
  • disabled location service.

Primary entry point: JCSWeatherError.h

Author

jerryga, [email protected]

License

JCSWeatherKit is available under the MIT license. See the LICENSE file for more info.

You might also like...
Simple and minimalist weather app that displays the current conditions.
Simple and minimalist weather app that displays the current conditions.

Minimalistic Weather App Project Description In this project, I have developed a simple and minimalist weather app, where I use the Current Weather Da

IOSWeather - An app that allows people to get weather forecast

iOSWeather iOSWeather is an app that allows people to get weather forecast. App

Get location of user and show near cities and weather of the cities for next 6 days. (iOS)

technical-assignment-Weather-App This project written in Swift by Emre Kılınc You need to have Xcode installed. Please open weather_app.xcworkspace wi

A Simple Weather App Using the Open Weather Map api

The Weather, a Simple Weather App Using the Open Weather Map api. This app demos use of the Open Weather Map api. The UI is simple, with views of the

A SwiftUI Weather App powered by World Weather Online API
A SwiftUI Weather App powered by World Weather Online API

SwiftUI-Weather The SwiftUI Weather app, allow users get the current weather for a particular locatio and view a 5-day weather forecast for the select

Simple Weather app to display future weather of 3 cities

WeatherApp Simple Weather app to display future weather of 3 cities Test project for a small weather application Overview For the test project a small

Swift Language Weather is an iOS weather app developed in Swift
Swift Language Weather is an iOS weather app developed in Swift

Swift Language Weather SwiftWeather has renamed to Swift Language Weather. Because this repo is ranked number one in Google when we search "Swift Weat

Weather-app - Created a simple weather app on Xcode using SwiftUI, only shows one location

weather-app Created a simple weather app on Xcode using SwiftUI, only shows one

Ios-weather-app - A simple weather app with swift
Ios-weather-app - A simple weather app with swift

AHOY Assignment Weather app Main Screen Settings Architecture The Architecture u

Owner
Asa. Ga
Asa. Ga
LiveWeatherApp - Live Weather App - Displays Live Weather Data with OpenWeather API

Live Weather App - Displays Live Weather Data with OpenWeather API Learned about

Matt Wong 1 Feb 5, 2022
Weather - Use Open weather APIs to fetch live weather data

Weather ??️ Use Open weather APIs to fetch live weather data Use Core Location p

Vicky Lee 2 Jun 3, 2022
Weather Forecast App (OpenWeather API & CLLocationManager). Clean Swift VIP architecture.

WeatherApp Weather Forecast App (OpenWeather API & CLLocationManager). Clean Swift VIP architecture. Without storyboard or xib. The application shows

Nikita Lomovtsev 7 Dec 25, 2022
WeatherSampleApp - Weather Sample app with SwiftUI consuming data from OpenWeather and using CoreLocation

WeatherSampleApp Weather application using SwiftUI Uses data provided by https:/

Juan Carlos Pazos 3 Jan 14, 2022
Weather forecast app that allows the user to either look for weather at their current location based on the GPS data or search for another city manually.

⛅️ Cloudy Weather forecast app that allows the user to either look for weather at their current location based on the GPS data or search for another c

Burhan 0 Nov 7, 2021
Weather App with widget that fetches real weather data using the Open Weather API

WeatherExtension App Demo WeatherExtension.mp4 Description Weather App that fetches real weather data using the Open Weather API Getting Started clone

Kayla Golder 0 Oct 21, 2021
CZWeatherKit is a simple, extensible weather library for iOS, tvOS, and OS X that allows for easy fetching of weather data from various weather services.

CZWeatherKit is a simple, extensible weather library for iOS, tvOS, and OS X that allows for easy fetching of weather data from various weather services.

Comyar 455 Nov 20, 2022
Apple Maps combined with the OpenWeather API written in SwiftUI

TempAtlas in SwiftUI TemperatureAtlas uses Apple Maps combined with the OpenWeather API written in SwiftUI. This project was built to explore SwiftUI

Justin Hatin 13 Apr 19, 2022
Want to know the current weather around the globe? Clima has your back!

Clima (a weather app) Dreaming about going on vacation somewhere? Use Clima to find real time weather from around the world or use your GPS to get loc

null 0 Dec 27, 2021
Application that displays current weather at a random location. iOS 14.0 or newer. SwiftUI.

Elseweather App that displays current weather at a random location. Description Elseweather was created as a student/research project with no practica

Ярослав 11 Dec 15, 2022