12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- /*****************************************************************************
- * LibrarySearchDataSource.swift
- * VLC for iOS
- *****************************************************************************
- * Copyright (c) 2019 VideoLAN. All rights reserved.
- * $Id$
- *
- * Authors: Carola Nitz <caro # videolan.org>
- *
- * Refer to the COPYING file of the official project for license.
- *****************************************************************************/
- class LibrarySearchDataSource: NSObject {
- var searchData = [VLCMLObject]()
- var model: MediaLibraryBaseModel
- init(model: MediaLibraryBaseModel) {
- self.model = model
- super.init()
- shouldReloadFor(searchString: "")
- }
- func objectAtIndex(index: Int) -> VLCMLObject? {
- return index < searchData.count ? searchData[index] : nil
- }
- func shouldReloadFor(searchString: String) {
- guard searchString != "" else {
- searchData = model.anyfiles
- return
- }
- searchData.removeAll()
- let lowercaseSearchString = searchString.lowercased()
- model.anyfiles.forEach {
- guard let searchableFile = $0 as? SearchableMLModel else {
- assertionFailure("LibrarySearchDataSource: Unhandled type")
- return
- }
- if searchableFile.contains(lowercaseSearchString) {
- searchData.append($0)
- }
- }
- }
- }
|