在使用firestore
使用过滤器时,如何避免编写大量代码?
我使用tableView
和didSelect
方法收集数据以开始使用过滤器
现在,我有近100多个过滤器参数。我的参数在tableViewCell
中。收集时,需要在Firestore query
中传递我选择的参数。
现在我的代码如下:
protocol FilterTableViewControllerDelegate: NSObjectProtocol {
func controller(_ controller: FilterTableViewController,
didSelectCategory childrensInterior: String?,
imitationKitchenInterior: String?,
loftInterior: String?,
retroInterior: String?,
cycloramaAccessories: String?,
bedAccessories: String?,
...+50 parameters
bathAccessories: String?,
fireplaceAccessories: String?,
swingAccessories: String?,
LargeWindowsOpporunities: String?,
minPriceLabel: Int?,
maxPriceLabel: Int?)
}
class FilterTableViewController: UITableViewController {
private var sections: [Section] = []
weak var delegate: FilterTableViewControllerDelegate?
static func fromStoryboard(delegate: FilterTableViewControllerDelegate? = nil) -> (navigationController: UINavigationController, filtersController: FilterTableViewController) {
let navController = UIStoryboard(name: "Main", bundle: nil).instantiateViewController(withIdentifier: "FilterViewController") as! UINavigationController
let controller = navController.viewControllers[0] as! FilterTableViewController
controller.delegate = delegate
return (navigationController: navController, filtersController: controller)
}
@IBAction func applyButton(_ sender: Any) {
delegate?.controller(self, didSelectCategory: childrensInterior,
imitationKitchenInterior: imitationKitchenInterior,
loftInterior: loftInterior,
retroInterior: retroInterior,
cycloramaAccessories: cycloramaAccessories,
bedAccessories: bedAccessories,
...+50 parameters
bathAccessories: bathAccessories,
fireplaceAccessories: fireplaceAccessories,
swingAccessories: swingAccessories,
LargeWindowsOpporunities: LargeWindowsOpporunities,
minPriceLabel: Int(minPriceLabel.text!),
maxPriceLabel: Int(maxPriceLabel.text!))
navigationController?.dismiss(animated: true, completion: nil)
}
}
例如,现在我一次收集一件东西:
override func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
if indexPath.section == 0 {
if indexPath.row == 0 {
self.imitationKitchenInterior = "imitationKitchenInterior"
} else if indexPath.row == 1 {
self.loftInterior = "loftInterior"
}
} else if indexPath.section == 1 {
if indexPath.row == 0 {
self.swingAccessories = "swingAccessories"
}
}
and etc...
}
如何不绘制didSelect
方法中每个参数的变化?或者,也许我需要使用dictionary
或array
在tableView
中显示数据,并使用dictionary
或array
来收集{{1} }?以及如何使用最少的代码来应用收集的数据来传递query firestore
?