This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import SwiftUI | |
| import MapKit | |
| struct ContentView: View { | |
| // MARK: - Properties | |
| @State private var centerCoordinate = CLLocationCoordinate2D() | |
| @State private var locations = [MKPointAnnotation]() | |
| @State private var selectedPlace: MKPointAnnotation? | |
| @State private var showingPlaceDetails = false | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import MapKit | |
| import SwiftUI | |
| struct MapView: UIViewRepresentable { | |
| @Binding var centerCoordinate: CLLocationCoordinate2D | |
| @Binding var selectedPlace: MKPointAnnotation? | |
| @Binding var showingPlaceDetails: Bool | |
| var annotations: [MKPointAnnotation] | |
| class Coordinator: NSObject, MKMapViewDelegate { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct BiometricAuth: View { | |
| // MARK: - Properties | |
| @State private var isUnlocked = false | |
| // MARK: - Body | |
| var body: some View { | |
| VStack { | |
| if isUnlocked { | |
| Text("Unlocked") | |
| } else { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| func authenticate() { | |
| let context = LAContext() | |
| var error: NSError? | |
| if context.canEvaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, error: &error) { | |
| let reason = "We need to unlock your data." | |
| context.evaluatePolicy(.deviceOwnerAuthenticationWithBiometrics, localizedReason: reason) { success, authError in | |
| DispatchQueue.main.async { | |
| if success { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import MapKit | |
| import SwiftUI | |
| struct MapView: UIViewRepresentable { | |
| class Coordinator: NSObject, MKMapViewDelegate { | |
| var parent: MapView | |
| init(_ parent: MapView) { | |
| self.parent = parent | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import MapKit | |
| import SwiftUI | |
| struct MapView: UIViewRepresentable { | |
| func makeUIView(context: Context) -> MKMapView { | |
| let mapView = MKMapView() | |
| return mapView | |
| } //: makeUIView func | |
| func updateUIView(_ view: MKMapView, context: Context) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // MARK: - Body | |
| var body: some View { | |
| Group { | |
| if loadingState == .loading { | |
| LoadingView() | |
| } else if loadingState == .success { | |
| SuccessView() | |
| } else if loadingState == .failed { | |
| FailedView() | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct LoadingView: View { | |
| var body: some View { | |
| Text("Loading...") | |
| } | |
| } //: LoadingView | |
| struct SuccessView: View { | |
| var body: some View { | |
| Text("Success") | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| struct SwitchingViewEnums: View { | |
| // MARK: - Properties | |
| enum LoadingState { | |
| case loading, success, failed | |
| } //: View State enum | |
| var loadingState = LoadingState.loading |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Text("Filemanager Bundle") | |
| .onTapGesture { | |
| let str2 = "Test 2" | |
| let path2 = FileManager.default.documentDirectory().appendingPathComponent("message2.txt") | |
| do { | |
| try str2.write(to: path2, atomically: true, encoding: .utf8) | |
| let input2 = try String(contentsOf: path2) | |
| print(input2) | |
| } catch { | |
| print(error.localizedDescription) |