passforios/passKit/Models/PasswordTableEntry.swift

44 lines
1.2 KiB
Swift
Raw Normal View History

2020-02-23 18:05:10 +08:00
//
// 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
2025-01-25 15:40:12 -08:00
public let isSynced: Bool
2020-02-23 18:05:10 +08:00
public let categoryText: String
2020-02-23 18:05:10 +08:00
public init(_ entity: PasswordEntity) {
self.passwordEntity = entity
2025-01-25 15:40:12 -08:00
self.title = entity.name
2020-02-23 18:05:10 +08:00
self.isDir = entity.isDir
2025-01-25 15:40:12 -08:00
self.isSynced = entity.isSynced
self.categoryText = entity.dirText
2020-02-23 18:05:10 +08:00
}
2021-08-26 23:12:13 +02:00
public func matches(_ searchText: String) -> Bool {
2025-01-25 15:40:12 -08:00
Self.match(nameWithCategory: passwordEntity.nameWithDir, searchText: searchText)
2020-02-23 18:05:10 +08:00
}
2020-02-23 18:05:10 +08:00
public static func match(nameWithCategory: String, searchText: String) -> Bool {
let titleSplit = nameWithCategory.split { !($0.isLetter || $0.isNumber || $0 == ".") }
2020-02-23 18:05:10 +08:00
for str in titleSplit {
if str.localizedCaseInsensitiveContains(searchText) {
2020-02-23 18:05:10 +08:00
return true
}
if searchText.localizedCaseInsensitiveContains(str) {
2020-02-23 18:05:10 +08:00
return true
}
}
2020-02-23 18:05:10 +08:00
return false
}
}