-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Feat:sparkles:: #32 Add AddressSearcher
- 주소 검색 기능을 담당하기 위한 AddressSearcher 클래스 추가
- Loading branch information
Showing
2 changed files
with
35 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
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 {} |