fix
This library supports Korean string initial matching(초성 매칭) and partial matching(부분 매칭).
To run the example project, clone the repo, and run pod install from the Example directory first.
pod install
let datas: [String] = ["예그리나", "늘품", "아슬라", "가온누리"] class ViewController: UIViewController, UITableViewDataSource, UITableViewDelegate, UISearchBarDelegate { var filteredData: [String] = [] let koreanStringSearchHelper: KoreanStringSearchHelper = KoreanStringSearchHelper(data: []) @IBAction func initialSwitchCallback(_ sender: UISwitch) { if sender.isOn { koreanStringSearchHelper.setInitialMatching(value: true) } else { koreanStringSearchHelper.setInitialMatching(value: false) } filteredData = koreanStringSearchHelper.getMatchedDatas(text: searchBar.text ?? "") table.reloadData() } @IBAction func partialSwitchCallback(_ sender: UISwitch) { if sender.isOn { koreanStringSearchHelper.setPartialMatching(value: true) } else { koreanStringSearchHelper.setPartialMatching(value: false) } filteredData = koreanStringSearchHelper.getMatchedDatas(text: searchBar.text ?? "") table.reloadData() } @IBOutlet weak var searchBar: UISearchBar! @IBOutlet weak var table: UITableView! override func viewDidLoad() { super.viewDidLoad() koreanStringSearchHelper.setDatas(datas: datas) self.table.dataSource = self self.table.delegate = self self.searchBar.delegate = self self.searchBar.placeholder = "검색어를 입력하세요." filteredData = datas } override func didReceiveMemoryWarning() { super.didReceiveMemoryWarning() // Dispose of any resources that can be recreated. } func searchBar(_ searchBar: UISearchBar, textDidChange searchText: String) { self.filteredData = koreanStringSearchHelper.getMatchedDatas(text: searchText) table.reloadData() } func searchBarTextDidBeginEditing(_ searchBar: UISearchBar) { self.searchBar.showsCancelButton = true } func searchBarCancelButtonClicked(_ searchBar: UISearchBar) { self.searchBar.showsCancelButton = false self.searchBar.text = "" self.searchBar.resignFirstResponder() } func searchBarSearchButtonClicked(_ searchBar: UISearchBar) { self.searchBar.showsCancelButton = false self.searchBar.text = "" self.searchBar.resignFirstResponder() } func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell { let cell: UITableViewCell = self.table.dequeueReusableCell(withIdentifier: "tableCell", for: indexPath) cell.textLabel?.text = filteredData[indexPath.row] return cell } func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int { return self.filteredData.count } }
Return data set that matches with given text.
Chooose whether user initial matching.
Chooose whether user partial matching.
Set data set to search.
Add data set to search.
Remove data set to search.
KoreanStringSearchHelper is available through CocoaPods. To install it, simply add the following line to your Podfile:
pod 'KoreanStringSearchHelper'
KoreanStringSearchHelper is available under the MIT license. See the LICENSE file for more info.
참고자료 http://minsone.github.io/mac/ios/linear-hangul-in-objective-c-swift
©Copyright 2023 CCF 开源发展委员会 Powered by Trustie& IntelliDE 京ICP备13000930号
KoreanStringSearchHelper
Summary
This library supports Korean string initial matching(초성 매칭) and partial matching(부분 매칭).
Demo App
To run the example project, clone the repo, and run
pod install
from the Example directory first.Example
Documentation
getMatchedDatas(text: String) -> [String]
Return data set that matches with given text.
setInitialMatching(value: Bool) -> void
Chooose whether user initial matching.
setPartialMatching(value: Bool) -> void
Chooose whether user partial matching.
setDatas(datas: [Stinrg]) -> void
Set data set to search.
addData(data: Stinrg) -> void
Add data set to search.
removeData(data: Stinrg) -> void
Remove data set to search.
Installation
KoreanStringSearchHelper is available through CocoaPods. To install it, simply add the following line to your Podfile:
License
KoreanStringSearchHelper is available under the MIT license. See the LICENSE file for more info.
참고자료 http://minsone.github.io/mac/ios/linear-hangul-in-objective-c-swift