diff --git a/Nav.xcodeproj/project.pbxproj b/Nav.xcodeproj/project.pbxproj index dcecd29..2782c70 100644 --- a/Nav.xcodeproj/project.pbxproj +++ b/Nav.xcodeproj/project.pbxproj @@ -16,8 +16,19 @@ 26A1500D29083A1300BC7355 /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26A1500C29083A1300BC7355 /* ContentView.swift */; }; 26A1500F29083A1400BC7355 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 26A1500E29083A1400BC7355 /* Assets.xcassets */; }; 26A1501929083B7B00BC7355 /* MapView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26A1501829083B7B00BC7355 /* MapView.swift */; }; + CE03E6792A1F77FA002AC26B /* Model.xcdatamodeld in Sources */ = {isa = PBXBuildFile; fileRef = CE03E6772A1F77FA002AC26B /* Model.xcdatamodeld */; }; CE2D8D3829C59D5F00E5C104 /* ImagePicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE2D8D3729C59D5F00E5C104 /* ImagePicker.swift */; }; CE2D8D3A29C59DF100E5C104 /* CategoryPicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE2D8D3929C59DF100E5C104 /* CategoryPicker.swift */; }; + CE34045D2A4FF7B80082D5EF /* PinInfo+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE3404552A4FF7B80082D5EF /* PinInfo+CoreDataClass.swift */; }; + CE34045E2A4FF7B80082D5EF /* PinInfo+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE3404562A4FF7B80082D5EF /* PinInfo+CoreDataProperties.swift */; }; + CE34045F2A4FF7B80082D5EF /* Theme+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE3404572A4FF7B80082D5EF /* Theme+CoreDataClass.swift */; }; + CE3404602A4FF7B80082D5EF /* Theme+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE3404582A4FF7B80082D5EF /* Theme+CoreDataProperties.swift */; }; + CE3404612A4FF7B80082D5EF /* Address+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE3404592A4FF7B80082D5EF /* Address+CoreDataClass.swift */; }; + CE3404622A4FF7B80082D5EF /* Address+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE34045A2A4FF7B80082D5EF /* Address+CoreDataProperties.swift */; }; + CE3404632A4FF7B80082D5EF /* Pictures+CoreDataClass.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE34045B2A4FF7B80082D5EF /* Pictures+CoreDataClass.swift */; }; + CE3404642A4FF7B80082D5EF /* Pictures+CoreDataProperties.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE34045C2A4FF7B80082D5EF /* Pictures+CoreDataProperties.swift */; }; + CE34046F2A5013E40082D5EF /* TestMapView.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE34046E2A5013E40082D5EF /* TestMapView.swift */; }; + CE3404712A501E9F0082D5EF /* LocationManager.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE3404702A501E9F0082D5EF /* LocationManager.swift */; }; DCE7EBCF2A172C1E00644745 /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCE7EBCE2A172C1E00644745 /* Extensions.swift */; }; DCE7EBD12A172C9000644745 /* SearchBar.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCE7EBD02A172C9000644745 /* SearchBar.swift */; }; FD33891A2917B81E00C4AB98 /* ListView.swift in Sources */ = {isa = PBXBuildFile; fileRef = FD3389192917B81E00C4AB98 /* ListView.swift */; }; @@ -37,8 +48,19 @@ 26A1500C29083A1300BC7355 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = ""; }; 26A1500E29083A1400BC7355 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = ""; }; 26A1501829083B7B00BC7355 /* MapView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapView.swift; sourceTree = ""; }; + CE03E6782A1F77FA002AC26B /* Model.xcdatamodel */ = {isa = PBXFileReference; explicitFileType = wrapper.xcdatamodel; path = Model.xcdatamodel; sourceTree = ""; }; CE2D8D3729C59D5F00E5C104 /* ImagePicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImagePicker.swift; sourceTree = ""; }; CE2D8D3929C59DF100E5C104 /* CategoryPicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CategoryPicker.swift; sourceTree = ""; }; + CE3404552A4FF7B80082D5EF /* PinInfo+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PinInfo+CoreDataClass.swift"; sourceTree = ""; }; + CE3404562A4FF7B80082D5EF /* PinInfo+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "PinInfo+CoreDataProperties.swift"; sourceTree = ""; }; + CE3404572A4FF7B80082D5EF /* Theme+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Theme+CoreDataClass.swift"; sourceTree = ""; }; + CE3404582A4FF7B80082D5EF /* Theme+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Theme+CoreDataProperties.swift"; sourceTree = ""; }; + CE3404592A4FF7B80082D5EF /* Address+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Address+CoreDataClass.swift"; sourceTree = ""; }; + CE34045A2A4FF7B80082D5EF /* Address+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Address+CoreDataProperties.swift"; sourceTree = ""; }; + CE34045B2A4FF7B80082D5EF /* Pictures+CoreDataClass.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Pictures+CoreDataClass.swift"; sourceTree = ""; }; + CE34045C2A4FF7B80082D5EF /* Pictures+CoreDataProperties.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Pictures+CoreDataProperties.swift"; sourceTree = ""; }; + CE34046E2A5013E40082D5EF /* TestMapView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = TestMapView.swift; sourceTree = ""; }; + CE3404702A501E9F0082D5EF /* LocationManager.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LocationManager.swift; sourceTree = ""; }; DCE7EBCE2A172C1E00644745 /* Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = ""; }; DCE7EBD02A172C9000644745 /* SearchBar.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SearchBar.swift; sourceTree = ""; }; FD3389192917B81E00C4AB98 /* ListView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ListView.swift; sourceTree = ""; }; @@ -92,6 +114,8 @@ 26A1501029083A1400BC7355 /* Preview Content */, CE2D8D3729C59D5F00E5C104 /* ImagePicker.swift */, CE2D8D3929C59DF100E5C104 /* CategoryPicker.swift */, + CE3404702A501E9F0082D5EF /* LocationManager.swift */, + CE03E6772A1F77FA002AC26B /* Model.xcdatamodeld */, ); path = Nav; sourceTree = ""; @@ -106,6 +130,14 @@ 26FE54E62949B90100B4E0E9 /* Data */ = { isa = PBXGroup; children = ( + CE3404552A4FF7B80082D5EF /* PinInfo+CoreDataClass.swift */, + CE3404562A4FF7B80082D5EF /* PinInfo+CoreDataProperties.swift */, + CE3404572A4FF7B80082D5EF /* Theme+CoreDataClass.swift */, + CE3404582A4FF7B80082D5EF /* Theme+CoreDataProperties.swift */, + CE3404592A4FF7B80082D5EF /* Address+CoreDataClass.swift */, + CE34045A2A4FF7B80082D5EF /* Address+CoreDataProperties.swift */, + CE34045B2A4FF7B80082D5EF /* Pictures+CoreDataClass.swift */, + CE34045C2A4FF7B80082D5EF /* Pictures+CoreDataProperties.swift */, FDFD7A642928993A001BE945 /* MockData.json */, ); path = Data; @@ -126,6 +158,7 @@ 262C17BD290CDF6900450E54 /* PinCreationView.swift */, FD3389192917B81E00C4AB98 /* ListView.swift */, DCE7EBD02A172C9000644745 /* SearchBar.swift */, + CE34046E2A5013E40082D5EF /* TestMapView.swift */, ); path = View; sourceTree = ""; @@ -146,14 +179,6 @@ path = Extension; sourceTree = ""; }; - 26FE54E62949B90100B4E0E9 /* Data */ = { - isa = PBXGroup; - children = ( - FDFD7A642928993A001BE945 /* MockData.json */, - ); - path = Data; - sourceTree = ""; - }; /* End PBXGroup section */ /* Begin PBXNativeTarget section */ @@ -226,19 +251,30 @@ files = ( CE2D8D3829C59D5F00E5C104 /* ImagePicker.swift in Sources */, 26A1500D29083A1300BC7355 /* ContentView.swift in Sources */, + CE3404642A4FF7B80082D5EF /* Pictures+CoreDataProperties.swift in Sources */, 262C17C2290D090C00450E54 /* Font+.swift in Sources */, 262C17C6290E385E00450E54 /* Text+.swift in Sources */, + CE34046F2A5013E40082D5EF /* TestMapView.swift in Sources */, 262C17C0290D06F700450E54 /* Color+.swift in Sources */, + CE34045D2A4FF7B80082D5EF /* PinInfo+CoreDataClass.swift in Sources */, FDFD7A6129289926001BE945 /* Bundle+Ext.swift in Sources */, + CE3404622A4FF7B80082D5EF /* Address+CoreDataProperties.swift in Sources */, 262C17CE290E9D4500450E54 /* Image+.swift in Sources */, 26A1501929083B7B00BC7355 /* MapView.swift in Sources */, + CE3404712A501E9F0082D5EF /* LocationManager.swift in Sources */, + CE03E6792A1F77FA002AC26B /* Model.xcdatamodeld in Sources */, DCE7EBD12A172C9000644745 /* SearchBar.swift in Sources */, + CE34045F2A4FF7B80082D5EF /* Theme+CoreDataClass.swift in Sources */, FDFD7A6329289933001BE945 /* MockDatum.swift in Sources */, + CE34045E2A4FF7B80082D5EF /* PinInfo+CoreDataProperties.swift in Sources */, DCE7EBCF2A172C1E00644745 /* Extensions.swift in Sources */, FD33891A2917B81E00C4AB98 /* ListView.swift in Sources */, + CE3404612A4FF7B80082D5EF /* Address+CoreDataClass.swift in Sources */, + CE3404632A4FF7B80082D5EF /* Pictures+CoreDataClass.swift in Sources */, CE2D8D3A29C59DF100E5C104 /* CategoryPicker.swift in Sources */, 26A1500B29083A1300BC7355 /* NavApp.swift in Sources */, 262C17BE290CDF6900450E54 /* PinCreationView.swift in Sources */, + CE3404602A4FF7B80082D5EF /* Theme+CoreDataProperties.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -439,6 +475,19 @@ defaultConfigurationName = Release; }; /* End XCConfigurationList section */ + +/* Begin XCVersionGroup section */ + CE03E6772A1F77FA002AC26B /* Model.xcdatamodeld */ = { + isa = XCVersionGroup; + children = ( + CE03E6782A1F77FA002AC26B /* Model.xcdatamodel */, + ); + currentVersion = CE03E6782A1F77FA002AC26B /* Model.xcdatamodel */; + path = Model.xcdatamodeld; + sourceTree = ""; + versionGroupType = wrapper.xcdatamodel; + }; +/* End XCVersionGroup section */ }; rootObject = 26A14FFF29083A1300BC7355 /* Project object */; } diff --git a/Nav/ContentView.swift b/Nav/ContentView.swift index e85df69..a2bb765 100644 --- a/Nav/ContentView.swift +++ b/Nav/ContentView.swift @@ -8,9 +8,12 @@ import SwiftUI struct ContentView: View { + @StateObject var locationManager = LocationManager() + var body: some View { TabView { MapView() + .environmentObject(locationManager) .tabItem { Image(systemName: "map") } @@ -21,6 +24,7 @@ struct ContentView: View { } PinCreationView() + .environmentObject(locationManager) .tabItem { Image(systemName: "plus") } @@ -30,6 +34,8 @@ struct ContentView: View { struct ContentView_Previews: PreviewProvider { static var previews: some View { - ContentView() + + ContentView().environmentObject(LocationManager()) +// ContentView() } } diff --git a/Nav/Data/Address+CoreDataClass.swift b/Nav/Data/Address+CoreDataClass.swift new file mode 100644 index 0000000..c435d04 --- /dev/null +++ b/Nav/Data/Address+CoreDataClass.swift @@ -0,0 +1,15 @@ +// +// Address+CoreDataClass.swift +// Nav +// +// Created by 박재경 on 2023/07/01. +// +// + +import Foundation +import CoreData + +@objc(Address) +public class Address: PinInfo { + +} diff --git a/Nav/Data/Address+CoreDataProperties.swift b/Nav/Data/Address+CoreDataProperties.swift new file mode 100644 index 0000000..f7af693 --- /dev/null +++ b/Nav/Data/Address+CoreDataProperties.swift @@ -0,0 +1,29 @@ +// +// Address+CoreDataProperties.swift +// Nav +// +// Created by 박재경 on 2023/07/01. +// +// + +import Foundation +import CoreData + + +extension Address { + + @nonobjc public class func fetchRequest() -> NSFetchRequest
{ + return NSFetchRequest
(entityName: "Address") + } + + @NSManaged public var city: String? + @NSManaged public var country: String? + @NSManaged public var detailAddress: String? + @NSManaged public var district: String? + @NSManaged public var postalCode: Int16 + @NSManaged public var streetAddress: String? + @NSManaged public var longitude: Double + @NSManaged public var latitude: Double + @NSManaged public var relationship: PinInfo? + +} diff --git a/Nav/Data/Pictures+CoreDataClass.swift b/Nav/Data/Pictures+CoreDataClass.swift new file mode 100644 index 0000000..2e5a5f8 --- /dev/null +++ b/Nav/Data/Pictures+CoreDataClass.swift @@ -0,0 +1,15 @@ +// +// Pictures+CoreDataClass.swift +// Nav +// +// Created by 박재경 on 2023/07/01. +// +// + +import Foundation +import CoreData + +@objc(Pictures) +public class Pictures: PinInfo { + +} diff --git a/Nav/Data/Pictures+CoreDataProperties.swift b/Nav/Data/Pictures+CoreDataProperties.swift new file mode 100644 index 0000000..f1722f0 --- /dev/null +++ b/Nav/Data/Pictures+CoreDataProperties.swift @@ -0,0 +1,22 @@ +// +// Pictures+CoreDataProperties.swift +// Nav +// +// Created by 박재경 on 2023/07/01. +// +// + +import Foundation +import CoreData + + +extension Pictures { + + @nonobjc public class func fetchRequest() -> NSFetchRequest { + return NSFetchRequest(entityName: "Pictures") + } + + @NSManaged public var img: Data? + @NSManaged public var relationship: PinInfo? + +} diff --git a/Nav/Data/PinInfo+CoreDataClass.swift b/Nav/Data/PinInfo+CoreDataClass.swift new file mode 100644 index 0000000..8c6b34d --- /dev/null +++ b/Nav/Data/PinInfo+CoreDataClass.swift @@ -0,0 +1,15 @@ +// +// PinInfo+CoreDataClass.swift +// Nav +// +// Created by 박재경 on 2023/07/01. +// +// + +import Foundation +import CoreData + +@objc(PinInfo) +public class PinInfo: Theme { + +} diff --git a/Nav/Data/PinInfo+CoreDataProperties.swift b/Nav/Data/PinInfo+CoreDataProperties.swift new file mode 100644 index 0000000..4a8efd5 --- /dev/null +++ b/Nav/Data/PinInfo+CoreDataProperties.swift @@ -0,0 +1,46 @@ +// +// PinInfo+CoreDataProperties.swift +// Nav +// +// Created by 박재경 on 2023/07/01. +// +// + +import Foundation +import CoreData + + +extension PinInfo { + + @nonobjc public class func fetchRequest() -> NSFetchRequest { + return NSFetchRequest(entityName: "PinInfo") + } + + @NSManaged public var content: String? + @NSManaged public var createDate: Date? + @NSManaged public var id: UUID? + @NSManaged public var rating: NSNumber? + @NSManaged public var title: String? + @NSManaged public var updateDate: Date? + @NSManaged public var address: Address? + @NSManaged public var pictures: NSSet? + @NSManaged public var theme: Theme? + +} + +// MARK: Generated accessors for pictures +extension PinInfo { + + @objc(addPicturesObject:) + @NSManaged public func addToPictures(_ value: Pictures) + + @objc(removePicturesObject:) + @NSManaged public func removeFromPictures(_ value: Pictures) + + @objc(addPictures:) + @NSManaged public func addToPictures(_ values: NSSet) + + @objc(removePictures:) + @NSManaged public func removeFromPictures(_ values: NSSet) + +} diff --git a/Nav/Data/Theme+CoreDataClass.swift b/Nav/Data/Theme+CoreDataClass.swift new file mode 100644 index 0000000..0f498fb --- /dev/null +++ b/Nav/Data/Theme+CoreDataClass.swift @@ -0,0 +1,15 @@ +// +// Theme+CoreDataClass.swift +// Nav +// +// Created by 박재경 on 2023/07/01. +// +// + +import Foundation +import CoreData + +@objc(Theme) +public class Theme: NSManagedObject { + +} diff --git a/Nav/Data/Theme+CoreDataProperties.swift b/Nav/Data/Theme+CoreDataProperties.swift new file mode 100644 index 0000000..00958df --- /dev/null +++ b/Nav/Data/Theme+CoreDataProperties.swift @@ -0,0 +1,43 @@ +// +// Theme+CoreDataProperties.swift +// Nav +// +// Created by 박재경 on 2023/07/01. +// +// + +import Foundation +import CoreData + + +extension Theme { + + @nonobjc public class func fetchRequest() -> NSFetchRequest { + return NSFetchRequest(entityName: "Theme") + } + + @NSManaged public var name: String? + @NSManaged public var pin: NSSet? + +} + +// MARK: Generated accessors for pin +extension Theme { + + @objc(addPinObject:) + @NSManaged public func addToPin(_ value: PinInfo) + + @objc(removePinObject:) + @NSManaged public func removeFromPin(_ value: PinInfo) + + @objc(addPin:) + @NSManaged public func addToPin(_ values: NSSet) + + @objc(removePin:) + @NSManaged public func removeFromPin(_ values: NSSet) + +} + +extension Theme : Identifiable { + +} diff --git a/Nav/LocationManager.swift b/Nav/LocationManager.swift new file mode 100644 index 0000000..c4f0d28 --- /dev/null +++ b/Nav/LocationManager.swift @@ -0,0 +1,7 @@ +import SwiftUI +import Combine + +class LocationManager: ObservableObject { + @Published var latitude: Double = 0.0 + @Published var longitude: Double = 0.0 +} diff --git a/Nav/MapModel.xcdatamodeld/MapModel.xcdatamodel/contents b/Nav/MapModel.xcdatamodeld/MapModel.xcdatamodel/contents new file mode 100644 index 0000000..df719de --- /dev/null +++ b/Nav/MapModel.xcdatamodeld/MapModel.xcdatamodel/contents @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/Nav/Model.xcdatamodeld/Model.xcdatamodel/contents b/Nav/Model.xcdatamodeld/Model.xcdatamodel/contents new file mode 100644 index 0000000..5fc16e6 --- /dev/null +++ b/Nav/Model.xcdatamodeld/Model.xcdatamodel/contents @@ -0,0 +1,33 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/Nav/View/MapView.swift b/Nav/View/MapView.swift index e4327d8..0b7a04b 100644 --- a/Nav/View/MapView.swift +++ b/Nav/View/MapView.swift @@ -4,10 +4,12 @@ // // Created by 김민택 on 2022/10/26. // -import MapKit import SwiftUI +import MapKit + struct MapView: View { private var mockDatas: [MockDatum] = MockDatum.allData + @EnvironmentObject var locationManager: LocationManager @State var searchQueryString = "" @@ -20,11 +22,12 @@ struct MapView: View { var body: some View { NavigationView { ZStack { - Map(coordinateRegion: $region, - showsUserLocation: false, - annotationItems: mockDatas){ - data in MapMarker(coordinate: data.coordinate) - } +// Map(coordinateRegion: $region, +// showsUserLocation: false, +// annotationItems: mockDatas){ +// data in MapMarker(coordinate: data.coordinate) +// } + TestMapView() HStack { Spacer() @@ -129,4 +132,4 @@ struct MapView_Previews: PreviewProvider { static var previews: some View { MapView() } -} \ No newline at end of file +} diff --git a/Nav/View/PinCreationView.swift b/Nav/View/PinCreationView.swift index fb92a77..c14a27e 100644 --- a/Nav/View/PinCreationView.swift +++ b/Nav/View/PinCreationView.swift @@ -6,12 +6,18 @@ // import SwiftUI import PhotosUI +import CoreData +import MapKit + struct PinCreationView: View { + @EnvironmentObject var locationManager: LocationManager + @Environment(\.managedObjectContext) var moc @State private var locationCategory: String = "음식" @State private var locationName: String = "" @State private var locationAddress: String = "" @State private var locationDescription: String = "" @State private var rating: [Bool] = [false, false, false, false, false] + var address = CLGeocoder.init() @StateObject var imagePicker = ImagePicker() let columns = [GridItem(.adaptive(minimum: 100))] @@ -133,7 +139,26 @@ struct PinCreationView: View { .padding(.bottom, 20) } - Button(action: {}) { + Button(action: { + let newTheme = Theme(context: self.moc) + newTheme.name = self.locationCategory + + let newPinInfo = PinInfo(context: self.moc) + newPinInfo.id = UUID.init() + newPinInfo.title = self.locationName + newPinInfo.content = self.locationDescription + newPinInfo.rating = (self.rating.filter { $0 }.count) as NSNumber + +// let newAddress = Address(context: self.moc) +// +// let newPictures = Pictures(context: self.moc) + + do { + try self.moc.save() + } catch { + print("저장하는 동안 에러 발생: \(error)") + } + }) { Text("확인") .headline() .foregroundColor(.navWhite) diff --git a/Nav/View/TestMapView.swift b/Nav/View/TestMapView.swift new file mode 100644 index 0000000..ddd915e --- /dev/null +++ b/Nav/View/TestMapView.swift @@ -0,0 +1,40 @@ +import SwiftUI +import MapKit + +struct TestMapView: UIViewRepresentable { + class Coordinator: NSObject, MKMapViewDelegate, UIGestureRecognizerDelegate { + var parent: TestMapView + + init(_ parent: TestMapView) { + self.parent = parent + } + + @objc func handleTap(sender: UITapGestureRecognizer) { + if sender.state == .ended { + let locationInView = sender.location(in: parent.mapView) + let tappedCoordinate = parent.mapView.convert(locationInView, toCoordinateFrom: parent.mapView) + + let latitude = tappedCoordinate.latitude + let longitude = tappedCoordinate.longitude + + print("Tapped Latitude: \(latitude), Longitude: \(longitude)") + } + } + } + + let mapView = MKMapView() + + func makeCoordinator() -> Coordinator { + Coordinator(self) + } + + func makeUIView(context: UIViewRepresentableContext) -> MKMapView { + let tapRecognizer = UITapGestureRecognizer(target: context.coordinator, action: #selector(Coordinator.handleTap(sender:))) + tapRecognizer.delegate = context.coordinator + mapView.addGestureRecognizer(tapRecognizer) + return mapView + } + + func updateUIView(_ view: MKMapView, context: UIViewRepresentableContext) { + } +}