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.

Overview

Deprecated, consider using Jupiter instead.

Build Status Version Carthage compatible Platform License git-brag-stats

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.

What's New in v2.2.7

Features
  • tvOS Support*.
  • Caching Support.
  • Support for historical and hourly data.
  • Request batching when using a weather service.
  • Improved request management when sending frequent requests.
  • Addition of more data, including humidity, wind speed, and more.

*Note: Features requiring MapKit are unsupported with tvOS.

Getting Started

CocoaPods

Add the following to your Podfile:

    pod "CZWeatherKit"

Usage

Included in this project is a Swift playground, CZWeatherKit.playground, that will let you play around with CZOpenWeatherMapRequest. However if you're as lazy as I am, here are some code snippets to get you started:

Wunderground

Getting Current Conditions, Obj-C
#import <CZWeatherKit/CZWeatherKit.h>

CZWundergroundRequest *request = [CZWundergroundRequest newConditionsRequest];
request.location = [CZWeatherLocation locationFromCity:@"Seattle" state:@"WA"];
request.key = @"wundergroundApiKey";
[request sendWithCompletion:^(CZWeatherData *data, NSError *error) {
	CZWeatherCurrentCondition *condition = data.current;
	// dreams come true here
}];
Getting Forecast Conditions, Swift
Void in if let weather = data { for forecast in weather.dailyForecasts { // dreams come true here } } }">
import CZWeatherKit

let request = CZWundergroundRequest.newForecastRequest()
request.location = CZWeatherLocation(fromCity: "Seattle", state: "WA")
request.key = "wundergroundApiKey"
request.sendWithCompletion { (data, error) -> Void in
    if let weather = data {
  		for forecast in weather.dailyForecasts {
  			// dreams come true here
  		}
    }
}

OpenWeatherMap

Getting Current Conditions, Obj-C
#import <CZWeatherKit/CZWeatherKit.h>

CZOpenWeatherMap *request = [CZOpenWeatherMapRequest newCurrentRequest];
request.location = [CZWeatherLocation locationFromCity:@"Seattle" state:@"WA"];
[request sendWithCompletion:^(CZWeatherData *data, NSError *error) {
	CZWeatherCurrentCondition *condition = data.current;
	// dreams come true here
}];
Getting Forecast Conditions, Swift
Void in if let weather = data { for forecast in weather.dailyForecasts { // dreams come true here } } }">
import CZWeatherKit

let request = CZOpenWeatherMapRequest.newDailyForecastRequestForDays(3)
request.location = CZWeatherLocation(fromCity: "Seattle", state: "WA")
request.sendWithCompletion { (data, error) -> Void in
    if let weather = data {
  		for forecast in weather.dailyForecasts {
  			// dreams come true here
  		}
    }
}

Using a Weather Service

A weather service allows for the dispatching of weather data requests and allows for more fine-grained control over how requests are handled as opposed to the interface provided by CZWeatherDataRequest. An ideal use case for a weather service is powering a weather app.

Void in if let weather = data { // dreams come true here } }) ">
import CZWeatherKit

let service = CZWeatherService()
request = CZOpenWeatherMapRequest.newCurrentRequest()
request.location = CZWeatherLocation(fromCity: "Seattle", state: "WA")
service.dispatchRequest(request, completion: { (data, error) -> Void in
    if let weather = data {
        // dreams come true here
    }
})

Supported Weather APIs

CZWeatherKit currently supports the following weather services:

Climacons

CZWeatherKit supports Climacons out of the box. The Climacons Font is a font set created by Adam Whitcroft featuring weather icons.

Architecture

Core Description
CZWeatherService Asyncronously dispatches requests, caches responses, and simplifies key management when making frequent API calls.
CZPINWeatherDataCache An implementation of the CZWeatherDataCache protocol that uses PINCache for caching weather data.
Model Type Description
CZWeatherLocation Represents a location to retrieve weather data for.
CZWeatherData Top-level container for all other weather data.
CZWeatherCurrentCondition Contains data for current conditions.
CZWeatherForecastCondition Contains data for a day's forecasted conditions.
CZWeatherHourlyCondition Contains data for an hour's conditions.
CZWeatherRequest The abstract base class for all request classes.
CZWundergroundRequest Used for calling the Wunderground API.
CZOpenWeatherMapRequest Used for calling the OpenWeatherMap API.
CZForecastioRequest Used for calling the Forecast.io API.
CZWorldWeatherOnlineRequest Used for calling the World Weather Online API.
API Type Description
CZWundergroundAPI Wunderground API class.
CZOpenWeatherMapAPI OpenWeatherMap API class.
CZForecastioAPI Forecastio API class.
CZWorldWeatherOnlineAPI WorldWeatherOnline API class.
Protocols Description
CZWeatherAPI The protocol for weather API classes.
CZWeatherDataCache The protocol for a cache used by a CZWeatherService.
Headers Description
CZClimacons Contains mappings for Climacons to chars.
CZWeatherKitTypes Contains varions type definitions.

Contributing

If you would like to contribute to the development of CZWeatherKit, please take care to follow the style conventions and please include unit tests in your pull request.

For feature requests or general questions, feel free to post an issue.

Contributers

Comments
  • Climacons not displaying in UILabel

    Climacons not displaying in UILabel

    I tried following the example on the cocoapods page as well as general advice on custom fonts and iOS etc, but no dice. It just shows the char mapped to the climacon, not the actual icon. See http://stackoverflow.com/questions/37199314/getting-climacons-to-display-in-uilabel-with-czweatherkit-in-swift

    opened by MadeByDouglas 7
  • -[NSNull objectForKeyedSubscript:]: unrecognized selector sent to instance 0x195fede70

    -[NSNull objectForKeyedSubscript:]: unrecognized selector sent to instance 0x195fede70

    We got a crash in -[CZOpenWeatherMapService parseCurrentConditionsFromJSON:](in MyWeatherCenter) (CZOpenWeatherMapService.m:146)

    What is the best way to handle this? Is it enough to check JSON for Null value in parseCurrentConditionsFromJSON?

    Thanks Sascha

    bug 
    opened by souhl 7
  • ClimaconCharacter change with Language

    ClimaconCharacter change with Language

    Hi,

    The ClimaconCharacter isn't the same when you change the language for the same city. For example: When I set the language to english, the ClimaconCharacter is '$'. But in French for the same city and the same time, the ClimaconCharacter is 'I'. But the summary is translate well. bug

    Best regards

    bug 
    opened by authiatr 6
  • Added World Weather Online as a service, and a few minor tweaks

    Added World Weather Online as a service, and a few minor tweaks

    I added World Weather Online as an available weather service, and updated one or two comments to be more descriptive/correct. I made the changes a while ago, but forgot to create a pull request and all.

    I've also merged the latest changes from your master branch back in, of course.

    opened by sebj 5
  • Feature/location class

    Feature/location class

    Hey, its stlunatic102 from reddit! I liked the work that you did and really wanted to see the change that I had mentioned integrated into your lib.

    I created a class called CZWeatherLocation that is used while creating the request. Each service is responsible for generating the query based on the state of this object right now, but it'd be great to see each service implement a protocol to serialize this object. Might generate some more maintainable code down the line rather than the giant if-else block that does the logic.

    Let me know what you think!

    opened by eliperkins 5
  • 2.2.3 doesn't work (same code works on 2.2.1)

    2.2.3 doesn't work (same code works on 2.2.1)

    Hello. It's me again.

    Well... Something is wrong with 2.2.3. It doesn't complete the weather request. Have no idea what is going on. Btw, I can show you my code.

    I'm going to work with 2.2.1 because it works fine. Need any help with debuggin? Just tell my how to help

    CZOpenWeatherMapRequest *request = [CZOpenWeatherMapRequest newCurrentRequest];
    request.location = [CZWeatherLocation locationFromCoordinate:CLLocationCoordinate2DMake(52.9661803, 87.9315624)];
    request.key = @"SOME KEY. DON'T WANT TO SHOW MINE";
    [request sendWithCompletion:^(CZWeatherData *data, NSError *error) {
        if (error == nil)
        {
            NSMutableDictionary *weather = [NSMutableDictionary new];
            [weather addEntriesFromDictionary:@{@"temperature":[NSNumber numberWithFloat:data.current.temperature.c]}];
            [weather addEntriesFromDictionary:@{@"humidity":[NSNumber numberWithFloat:data.current.humidity]}];
            [weather addEntriesFromDictionary:@{@"windspeed":[NSNumber numberWithFloat:data.current.windSpeed.kph / 3.6f]}];
            [weather addEntriesFromDictionary:@{@"climacon":[NSNumber numberWithInt:data.current.climacon]}];
            [weather addEntriesFromDictionary:@{@"date":[NSDate date]}];
            [[VKManager instance] setWeather:weather];
            [[NSUserDefaults standardUserDefaults] setObject:weather forKey:@"gesh.weather"];
            [[NSUserDefaults standardUserDefaults] synchronize];
        }
        else
        {
            static dispatch_once_t onceToken;
            dispatch_once(&onceToken, ^{
                [[VKManager instance] requestWeather];
            });
        }
    }];
    
    bug 
    opened by iwheelbuy 4
  • CZWeatherKit does not support historical data

    CZWeatherKit does not support historical data

    Would love to see CZWeatherKit support querying historical weather data (cf http://openweathermap.org/history). I may add this for my own purposes if it is not already planned…

    feature 
    opened by quicklywilliam 4
  • days property's value becomes 0 after CZWeatherRequest is copied

    days property's value becomes 0 after CZWeatherRequest is copied

    I was getting only 4 days of forecast no matter what i typed inside this method: CZOpenWeatherMapRequest.newDailyForecastRequestForDays(7)

    I noticed in CZWeatherRequest class // dispatchWithAPI method the [self copy] only retains feature string.

    bug 
    opened by alperg9 3
  • CZOpenWeatherMapRequest with location

    CZOpenWeatherMapRequest with location

    When using CZopenWeatherMapRequest with LocationFromCoordinate the API URL is incorrectly formatted http://api.openweathermap.org/data/2.5/weather?lat=51.2758,lon=-0.7763&lang=en&mode=json&APPID=XXXXX The lat and lon should be separated by an & not a ,

    I think the problem is componentForLocation in CZopenWeatherMapAPI

    bug 
    opened by paulgee31 3
  • Crash when archiving CZWeatherCurrentCondition, CZWeatherForecastCondition, CZWeatherHourlyCondition & CZWeatherLocation

    Crash when archiving CZWeatherCurrentCondition, CZWeatherForecastCondition, CZWeatherHourlyCondition & CZWeatherLocation

    When archiving a CZWeatherCurrentCondition, CZWeatherForecastCondition, CZWeatherHourlyCondition or CZWeatherLocation object the application crash. The crash is due to a bug when archiving structs.

    Execution of:

    [NSKeyedArchiver archiveRootObject:weatherData toFile:[NSTemporaryDirectory() stringByAppendingString:@"archive"]];
    

    Result in the following exception:

    Assertions: failed: caught "NSInvalidArgumentException", "*** -[NSKeyedArchiver encodeValueOfObjCType:at:]: this archiver cannot encode structs"
    (
        0   CoreFoundation                      0x000000010cc1df45 __exceptionPreprocess + 165
        1   libobjc.A.dylib                     0x000000010c697deb objc_exception_throw + 48
        2   CoreFoundation                      0x000000010cc1de7d +[NSException raise:format:] + 205
        3   Foundation                          0x000000010c302a32 -[NSKeyedArchiver encodeValueOfObjCType:at:] + 311
        4   Foundation                          0x000000010c329b4a -[NSValue encodeWithCoder:] + 317
        5   Foundation                          0x000000010c328f22 -[NSConcreteValue encodeWithCoder:] + 297
        6   Foundation                          0x000000010c2916c7 _encodeObject + 1259
        7   CZWeatherKit                        0x00000001167380e8 -[CZWeatherLocation encodeWithCoder:] + 284
        8   Foundation                          0x000000010c2916c7 _encodeObject + 1259
        9   Foundation                          0x000000010c2cc442 +[NSKeyedArchiver archiveRootObject:toFile:] + 241
        ...
    )
    

    The part the cause this crash is:

    NSValue *coordinateValue = [NSValue value:&_coordinate
                                     withObjCType:@encode(CLLocationCoordinate2D)];
    [aCoder encodeObject:coordinateValue forKey:@"coordinate"];
    

    It's correct to do this, but it's seams to be a knowing bug (rdar://8631663).

    An existing workaround is to archive/unarchive the values of the struct manually.

    Something like this:

    NSNumber *latitude = [NSNumber numberWithDouble:self.coordinate.latitude];
    NSNumber *longitude = [NSNumber numberWithDouble:self.coordinate.longitude];
    [aCoder encodeObject:latitude forKey:@"latitude"];
    [aCoder encodeObject:longitude forKey:@"longitude"];
    

    The problem is exactly the same with the structs CZHumidity, CZTemperature and CZWindDirection.

    I'm going to fix it on my side, and create a PR.

    Also if you know any better solution, said it!

    opened by awph 2
  • Duplicate case value: 'ClimaconFahrenheit' and 'ClimaconShowers' both equal '39'

    Duplicate case value: 'ClimaconFahrenheit' and 'ClimaconShowers' both equal '39'

    Duplicate case value: 'ClimaconFahrenheit' and 'ClimaconShowers' both equal '39'

    ClimaconFahrenheit = ''', ClimaconShowers = ''',

    opened by iwheelbuy 2
Releases(2.2.7)
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
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
BioMatrix is an app that allows users to quiz themselves on various biology questions!

Welcome to BioMatrix! It is an app that allows users to quiz themselves on a variety of biology questions! This app allows various functionalities!

null 6 May 28, 2022
WeatherApp - A simple weather app utilizing Google Places API for search and OpenWeather for weather data

Swift Weather App About A simple weather app utilizing Google Places API for sea

null 0 Jan 5, 2022
Exposing macOS Services through a Catalyst app

CatalystServices This is a simple example to show how you can implement the macOS Services system in your Catalyst app. The services you expose are pr

Steven Troughton-Smith 33 Oct 26, 2022
A mobile application project designed for everybody which provides the easiest way to make searchs for public services

A mobile application project designed for everybody which provides the easiest way to make searchs for public services

null 0 Nov 23, 2021
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
Ios-weather-app - A simple weather app with swift

AHOY Assignment Weather app Main Screen Settings Architecture The Architecture u

null 0 Jan 29, 2022
With the Coverless App, you can discover many books of various genres

Coverless Não julgue um livro pela capa: use a sinopse! Com o App Coverless, você pode descobrir muitos livros de vários gêneros. Salve seus livros de

Oliver (Bruno) 1 Oct 26, 2021
A multiplatform SwiftUI project demonstrating various SwiftUI features.

WikiDemo A multiplatform SwiftUI project demonstrating various SwiftUI features, including creating a master-detail interface. It's a multiplatform ve

Swift Dev Journal 6 Oct 17, 2022
CollectionComposer2 - Copy random image files from various sources to destination folder - ready to use

CollectionComposer2 This is a small tool to copy a random number of image files from different source folders to a destination folder. As an additiona

Holger Hinzberg 0 Jan 4, 2022
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

null 1 Feb 17, 2022
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

null 0 Nov 28, 2021
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

Rahul Kadiyala 1 Feb 11, 2022
A simple clean application to provide you with weather forecast data as well as currency rates, all with beautiful melodies and sounds

A simple clean application to provide you with weather forecast data as well as currency rates, all with beautiful melodies and sounds.

Sergey 1 Jan 21, 2022
A simple weather forecast application with data provided from OpenWeatherMap.

Weather Forecast Example Application Author: Long Kim This repo contains the source code for a simple weather forecast application with data provided

Long Kim H. 1 Sep 19, 2022
IOSWeather - An app that allows people to get weather forecast

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

null 0 Jan 13, 2022
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

Jake Lin 5.2k Jan 7, 2023