passforios/passKit/Models/PasswordTableEntry.swift
Danny Mösch 32b7c9b635
Some cleanup especially regarding method references (#516)
* Remove superfluous method arguments in method references

* Use 'Self' for internal static access

* Convert static to instance field in singleton class

* Remove class name prefix in references to local methods

* Remove nested frameworks in all extensions and frameworks
2021-10-02 20:46:07 -07:00

43 lines
1.2 KiB
Swift

//
// PasswordTableEntry.swift
// passKit
//
// Created by Yishi Lin on 2020/2/23.
// Copyright © 2020 Bob Sun. All rights reserved.
//
import Foundation
public class PasswordTableEntry: NSObject {
public let passwordEntity: PasswordEntity
@objc public let title: String
public let isDir: Bool
public let synced: Bool
public let categoryText: String
public init(_ entity: PasswordEntity) {
self.passwordEntity = entity
self.title = entity.name!
self.isDir = entity.isDir
self.synced = entity.synced
self.categoryText = entity.getCategoryText()
}
public func matches(_ searchText: String) -> Bool {
Self.match(nameWithCategory: passwordEntity.nameWithCategory, searchText: searchText)
}
public static func match(nameWithCategory: String, searchText: String) -> Bool {
let titleSplit = nameWithCategory.split { !($0.isLetter || $0.isNumber || $0 == ".") }
for str in titleSplit {
if str.localizedCaseInsensitiveContains(searchText) {
return true
}
if searchText.localizedCaseInsensitiveContains(str) {
return true
}
}
return false
}
}