-
-
Notifications
You must be signed in to change notification settings - Fork 106
/
Copy pathPasswordTableEntry.swift
43 lines (37 loc) · 1.21 KB
/
PasswordTableEntry.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//
// 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 isSynced: Bool
public let categoryText: String
public init(_ entity: PasswordEntity) {
self.passwordEntity = entity
self.title = entity.name
self.isDir = entity.isDir
self.isSynced = entity.isSynced
self.categoryText = entity.dirText
}
public func matches(_ searchText: String) -> Bool {
Self.match(nameWithCategory: passwordEntity.nameWithDir, 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
}
}