Dunfey · Hotel WWDC as data, est. 1983
Front desk everything
Years
Topics

2023 EssentialsDeveloper Tools

WWDC23 · 24 min · Essentials / Developer Tools

Prototype with Xcode Playgrounds

Speed up feature development by prototyping new code with Xcode Playgrounds, eliminating the need to keep rebuilding and relaunching your project to verify your changes. We’ll show you how using a playground in your project or package can help you try out your code in various scenarios and take a close look at the returned values, including complex structures and user interface elements, so you can quickly iterate on a feature before integrating it into your project.

Watch at developer.apple.com ↗

Transcript all transcripts

Chapters

  • 3:00 — Exploring the data model and inspecting UI snapshots
  • 14:26 — Becoming familiar with a new package
  • 18:07 — Using the Live View
  • 22:03 — Running the updated project

Code shown on screen · 15 snippets

birdsToShow computed property before the required changes swift · at 2:04 ↗
var birdsToShow: [Bird] {
    // TODO: Narrow down the list of birds to find.
    let birdProvider = BirdProvider(region: .northAmerica)
    return birdProvider.birds
}
birdProvider instance swift · at 4:15 ↗
let birdProvider = BirdProvider(region: .northAmerica)
CustomStringConvertible swift · at 6:31 ↗
extension Bird: CustomStringConvertible {
    
    public var description: String {
        return "\(commonName) (\(scientificName))"
    }
    
}
CustomPlaygroundDisplayConvertible swift · at 8:17 ↗
extension Bird: CustomPlaygroundDisplayConvertible {
    
    public var playgroundDescription: Any {
        return photo as Any
    }
    
}
Birds without a photo swift · at 9:45 ↗
let birdsToFind = birdProvider.birds.filter { $0.photo == nil }
Owls without a photo swift · at 10:52 ↗
let owlsToFind = birdsToFind.filter { $0.family == .owls }
Verifying the ChecklistView swift · at 11:15 ↗
let checklist = ChecklistView()
for bird in owlsToFind {
    checklist.add(bird)
}
birdsToShow computed property with the required changes swift · at 13:41 ↗
var birdsToShow: [Bird] {
    let birdProvider = BirdProvider(region: .northAmerica)
    let birdsToFind = birdProvider.birds.filter { $0.photo == nil }
    let owlsToFind = birdsToFind.filter { $0.family == .owls }
    return owlsToFind
}
sightingToShow function before the required changes swift · at 14:21 ↗
func sightingToShow(for bird: Bird) -> Sighting? {
    // TODO: Use BirdSightings package to fetch the most recent sighting.
    return nil
}
BirdSightings package example swift · at 15:04 ↗
let barnOwlCode = "BNOW"
let centralParkLocation = CLLocationCoordinate2D(latitude:  40.785091, longitude: -73.968285)

let sightingsProvider = SightingsProvider()
sightingsProvider.fetchSightings(of: barnOwlCode, around: centralParkLocation)
Parameters for sightings fetching swift · at 16:08 ↗
let bird = owlsToFind.first!
let appleParkLocation = CLLocationCoordinate2D(latitude: 37.3348655, longitude: 122.0089409)
Sightings fetching swift · at 17:31 ↗
let sightingsProvider = SightingsProvider()
let sightings = sightingsProvider.fetchSightings(of: bird.speciesCode, around: appleParkLocation)
Initializing the SightingMapView swift · at 18:23 ↗
let mostRecentSighting = sightings.first
let sightingMapView = SightingMapView(sighting: mostRecentSighting)
Setting up the playground's live view swift · at 18:55 ↗
import PlaygroundSupport
PlaygroundPage.current.liveView = sightingMapView
sightingToShow function with the required changes swift · at 22:20 ↗
func sightingToShow(for bird: Bird) -> Sighting? {
    let sightingsProvider = SightingsProvider()
    let sightings = sightingsProvider.fetchSightings(of: bird.speciesCode, around: lastCurrentLocation)
    let mostRecentSighting = sightings.first
    return mostRecentSighting
}