diff --git a/NationalWeatherService.playground/Contents.swift b/NationalWeatherService.playground/Contents.swift new file mode 100644 index 0000000..78cebe6 --- /dev/null +++ b/NationalWeatherService.playground/Contents.swift @@ -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 diff --git a/NationalWeatherService.playground/contents.xcplayground b/NationalWeatherService.playground/contents.xcplayground new file mode 100644 index 0000000..7627317 --- /dev/null +++ b/NationalWeatherService.playground/contents.xcplayground @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/NationalWeatherService.playground/timeline.xctimeline b/NationalWeatherService.playground/timeline.xctimeline new file mode 100644 index 0000000..bf468af --- /dev/null +++ b/NationalWeatherService.playground/timeline.xctimeline @@ -0,0 +1,6 @@ + + + + +