Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions NationalWeatherService.playground/Contents.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//: A MapKit based Playground

import MapKit
import NationalWeatherService
import CoreLocation
import PlaygroundSupport


let nws = NationalWeatherService(userAgent: "(github.com/WeatherProvider, NationalWeatherService-Swift)")
let location = CLLocationCoordinate2DMake(47.6174, -122.2017) // Bellvue, Washington

// Create a map annotation
let annotation = MKPointAnnotation()

annotation.coordinate = location
annotation.title = "title"
annotation.subtitle = "subtitle"

// Gets the forecast, organized into time periods (such as Afternoon, Evening, etc).
NationalWeatherService.units = .fahrenheit
nws.forecast(for: location) { result in
switch result {
case .success(let forecast):
print(forecast)

let period = forecast.periods.first!
print(period)

print(period.shortForecast)
annotation.title = period.shortForecast

print(period.detailedForecast)
annotation.subtitle = period.detailedForecast

case .failure(let error):
print(error)
}
}

// Now let's create a MKMapView
let mapView = MKMapView(frame: CGRect(x:0, y:0, width:640, height:480))

// Define a region for our map view
var mapRegion = MKCoordinateRegion()

let mapRegionSpan = 0.2
mapRegion.center = location
mapRegion.span.latitudeDelta = mapRegionSpan
mapRegion.span.longitudeDelta = mapRegionSpan

mapView.setRegion(mapRegion, animated: true)

mapView.addAnnotation(annotation)

// Add the created mapView to our Playground Live View
PlaygroundPage.current.liveView = mapView
4 changes: 4 additions & 0 deletions NationalWeatherService.playground/contents.xcplayground
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<playground version='5.0' target-platform='ios' buildActiveScheme='true' executeOnSourceChanges='false' importAppTypes='true'>
<timeline fileName='timeline.xctimeline'/>
</playground>
6 changes: 6 additions & 0 deletions NationalWeatherService.playground/timeline.xctimeline
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<Timeline
version = "3.0">
<TimelineItems>
</TimelineItems>
</Timeline>