import Basis
import LocalAuthentication
import MapKit
extension ContentView {
@MainActor class ViewModel: ObservableObject {
@Revealed var mapRegion = MKCoordinateRegion(middle: CLLocationCoordinate2D(latitude: 50, longitude: 0), span: MKCoordinateSpan(latitudeDelta: 25, longitudeDelta: 25))
@Revealed non-public(set)var areas: [Location]
@Revealed var selectedPlace: Location?
@Revealed var isUnlocked = false
@Revealed var authenticationFailed = false
@Revealed var noAuthenticationFound = false
@Revealed var alertMessage = “”
let savePath = FileManager.documentsDirectory.appendingPathExtension("SavePlace")
init() {
do {
let information = strive Information(contentsOf: savePath)
areas = strive JSONDecoder().decode([Location].self, from: information)
} catch {
areas = []
}
}
func save() {
do {
let information = strive JSONEncoder().encode(areas)
strive information.write(to: savePath, choices: [.atomicWrite, .completeFileProtection])
} catch {
print("Unable to avoid wasting information.")
}
}
func addLocation() {
let newlocation = Location(id: UUID(), title: "New location", description: "", latitude: mapRegion.middle.latitude, longitude: mapRegion.middle.longitude)
areas.append(newlocation)
save()
}
func replace(location: Location) {
guard let selectedPlace = selectedPlace else { return }
if let index = areas.firstIndex(of: selectedPlace) {
areas[index] = location
save()
}
}
func authenticate() {
let context = LAContext()
var error: NSError?
if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) {
let motive = "It's good to authenticate your self"
context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: motive) {success,authenticationError in
if success {
Process { @MainActor in
self.isUnlocked = true
}
} else {
Process { @MainActor in
self.authenticationFailed = true
self.alertMessage = "Sorry, we're unable to confirm it is you"
}
}
}
} else {
noAuthenticationFound = true
alertMessage = "Sorry your machine cannot perform authentications at this second"
}
}
}
}
///…………………………..
i’ve ContentView, EditView, and ResultView
that is the View mannequin for my content material view,how do i make a view mannequin for different views, do i add one other extension on this identical file or make new file, how do i am going about it.///
i added in identical file
extension EditView { /// for edit view
@MainActor class ViewModel: ObservableObject {}
it didn’t work.