TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

Day 73: Conceptual doubts

Forums > 100 Days of SwiftUI

Hello,

I just completed the challenges for Project 14. There are a couple of things I noticed while doing these tasks and I'm hoping someone here would have an explanation for it.

  1. In ContentView-ViewModel.swift we import CoreLocation to work with CLLocationCoordinate2D. Why wasn't CoreLocation imported in Location.swift?
  2. In Part 3 of the project (Selecting and editing map annotations), we change the id property of the Location struct to a variable, so as to assign to a new id while updating the location. Paul provides an explanation for it in the video. However, I changed it back to a constant property and the location gets updated just fine. Has anyone else noticed this?

I'm using Xcode 15.2 and deploying for iOS 17.0.1.

1      

The struct also contains a computed variable of type CLLocationCoordinate2D.

struct Location: Codable, Equatable, Identifiable {
    var id: UUID
    var name: String
    var description: String
    var latitude: Double
    var longitude: Double

    var coordinate: CLLocationCoordinate2D {
        CLLocationCoordinate2D(latitude: latitude, longitude: longitude)
    }
}

1      

Hacking with Swift is sponsored by Superwall.

SPONSORED Superwall lets you build & test paywalls without shipping updates. Run experiments, offer sales, segment users, update locked features and more at the click of button. Best part? It's FREE for up to 250 conversions / mo and the Superwall team builds out 100% custom paywalls – free of charge.

Learn More

Sponsor Hacking with Swift and reach the world's largest Swift community!

Reply to this topic…

You need to create an account or log in to reply.

All interactions here are governed by our code of conduct.

 
Unknown user

You are not logged in

Log in or create account
 

Link copied to your pasteboard.