Skip to content

Commit

Permalink
Feat:sparkles:: #32 Add AddressSearcher
Browse files Browse the repository at this point in the history
- 주소 검색 기능을 담당하기 위한 AddressSearcher 클래스 추가
  • Loading branch information
taek0622 committed Jun 2, 2023
1 parent 0080a85 commit ef9b833
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Nav.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
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 */; };
26A82ED82A29CCDE00C23407 /* AddressSearcher.swift in Sources */ = {isa = PBXBuildFile; fileRef = 26A82ED72A29CCDE00C23407 /* AddressSearcher.swift */; };
CE2D8D3829C59D5F00E5C104 /* ImagePicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE2D8D3729C59D5F00E5C104 /* ImagePicker.swift */; };
CE2D8D3A29C59DF100E5C104 /* CategoryPicker.swift in Sources */ = {isa = PBXBuildFile; fileRef = CE2D8D3929C59DF100E5C104 /* CategoryPicker.swift */; };
DCE7EBCF2A172C1E00644745 /* Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = DCE7EBCE2A172C1E00644745 /* Extensions.swift */; };
Expand All @@ -37,6 +38,7 @@
26A1500C29083A1300BC7355 /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
26A1500E29083A1400BC7355 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
26A1501829083B7B00BC7355 /* MapView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MapView.swift; sourceTree = "<group>"; };
26A82ED72A29CCDE00C23407 /* AddressSearcher.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AddressSearcher.swift; sourceTree = "<group>"; };
CE2D8D3729C59D5F00E5C104 /* ImagePicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ImagePicker.swift; sourceTree = "<group>"; };
CE2D8D3929C59DF100E5C104 /* CategoryPicker.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CategoryPicker.swift; sourceTree = "<group>"; };
DCE7EBCE2A172C1E00644745 /* Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Extensions.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -92,6 +94,7 @@
26A1501029083A1400BC7355 /* Preview Content */,
CE2D8D3729C59D5F00E5C104 /* ImagePicker.swift */,
CE2D8D3929C59DF100E5C104 /* CategoryPicker.swift */,
26A82ED72A29CCDE00C23407 /* AddressSearcher.swift */,
);
path = Nav;
sourceTree = "<group>";
Expand Down Expand Up @@ -227,6 +230,7 @@
CE2D8D3829C59D5F00E5C104 /* ImagePicker.swift in Sources */,
26A1500D29083A1300BC7355 /* ContentView.swift in Sources */,
262C17C2290D090C00450E54 /* Font+.swift in Sources */,
26A82ED82A29CCDE00C23407 /* AddressSearcher.swift in Sources */,
262C17C6290E385E00450E54 /* Text+.swift in Sources */,
262C17C0290D06F700450E54 /* Color+.swift in Sources */,
FDFD7A6129289926001BE945 /* Bundle+Ext.swift in Sources */,
Expand Down
31 changes: 31 additions & 0 deletions Nav/AddressSearcher.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// AddressSearcher.swift
// Nav
//
// Created by 김민택 on 2023/06/02.
//

import Combine
import Foundation
import MapKit
import SwiftUI

class AddressSearcher: NSObject, ObservableObject, MKLocalSearchCompleterDelegate {
@Published var searchQuery = ""
var completer: MKLocalSearchCompleter
@Published var completions: [MKLocalSearchCompletion] = []
var cancellable: AnyCancellable?

override init() {
completer = MKLocalSearchCompleter()
super.init()
cancellable = $searchQuery.assign(to: \.queryFragment, on: self.completer)
completer.delegate = self
}

func completerDidUpdateResults(_ completer: MKLocalSearchCompleter) {
self.completions = completer.results
}
}

extension MKLocalSearchCompletion: Identifiable {}

0 comments on commit ef9b833

Please sign in to comment.