I am getting an error, “Overriding declaration requires an 'override' keyword” in my init, but I don't understand what declaration I am overriding. Or even what, in simple terms, a declaration is.
class MyViewModel: NSObject, ObservableObject {
@Published var coolName: String = "”
@Published var coolLocation: String = "”
@Published private(set) var results: Array<AddressResult> = []
@Published var searchableText = "”
@Published var region = MKCoordinateRegion()
@Published private(set) var annotationItems: [AnnotationItem] = []
private var cancellables = Set<AnyCancellable>()
private lazy var localSearchCompleter: MKLocalSearchCompleter = {
let completer = MKLocalSearchCompleter()
completer.delegate = self
return completer
}()
init() {
observeSearchableText()
}
func observeSearchableText() {
$searchableText
.debounce(for: 0.8, scheduler: DispatchQueue.main)
.receive(on: DispatchQueue.main)
.sink(receiveValue: {[weak self] recievedValue in
self?.searchAddress(recievedValue)
})
.store(in: &cancellables)
}
CodePudding user response:
If you "inherit" from NSObject
you have to override
its initializer
class Somthing: NSObject{
override init() {
//You should also call the super class' initializer.
super.init()
}
}