Two implementation methods. If there are very few and stable entries, just get them as you do to reduce traffic and speed up search. Usually, the search content is passed to the backend, and the backend returns the search results.
Usually use HTTPRequest (NSURL, NSURLConnection, NSURLSession and other system built-in methods, or third-party libraries such as AFNetworking) to send a get or post request to the server, which contains the information you want to retrieve, such as product type, color, price etc., usually in JSON form. Then wait for the server to return the search results, usually in JSON format, and then display the content obtained from the server as the results.
If it is an enumeration type data, the options are limited. Of course, it is all placed on the client and then retrieved.
If, as you said, it is a commodity and the quantity is large, then it can only be put on the server for retrieval. After the user enters the keywords and clicks search, the keywords are sent to the server, and the server returns a list of search results. After the client receives it, it is displayed.
There is another method that wastes a little more traffic, but the user experience will be better: while the user is typing, the keywords are sent to the server for retrieval, and the retrieval results are displayed. As the content entered by the user changes, the retrieval results change accordingly. You can check out the ReactiveCocoa framework, it has some examples:
let searchStrings = textField.rac_textSignal()
.toSignalProducer()
.map { text in text as! String }
.throttle(0.5, onScheduler: QueueScheduler.mainQueueScheduler)
let searchResults = searchStrings
.flatMap(.Latest) { (query: String) -> SignalProducer<(NSData, NSURLResponse), NSError> in
let URLRequest = self.searchRequestWithEscapedQuery(query)
return NSURLSession.sharedSession()
.rac_dataWithRequest(URLRequest)
.retry(2)
.flatMapError { error in
print("Network error occurred: \(error)")
return SignalProducer.empty
}
}
.map { (data, URLResponse) -> String in
let string = String(data: data, encoding: NSUTF8StringEncoding)!
return self.parseJSONResultsFromString(string)
}
.observeOn(UIScheduler())
Two implementation methods. If there are very few and stable entries, just get them as you do to reduce traffic and speed up search.
Usually, the search content is passed to the backend, and the backend returns the search results.
Usually use HTTPRequest (NSURL, NSURLConnection, NSURLSession and other system built-in methods, or third-party libraries such as AFNetworking) to send a get or post request to the server, which contains the information you want to retrieve, such as product type, color, price etc., usually in JSON form. Then wait for the server to return the search results, usually in JSON format, and then display the content obtained from the server as the results.
If it is an enumeration type data, the options are limited. Of course, it is all placed on the client and then retrieved.
If, as you said, it is a commodity and the quantity is large, then it can only be put on the server for retrieval. After the user enters the keywords and clicks search, the keywords are sent to the server, and the server returns a list of search results. After the client receives it, it is displayed.
There is another method that wastes a little more traffic, but the user experience will be better: while the user is typing, the keywords are sent to the server for retrieval, and the retrieval results are displayed. As the content entered by the user changes, the retrieval results change accordingly. You can check out the ReactiveCocoa framework, it has some examples: