Fix searching with special characters
This commit is contained in:
parent
5394c13218
commit
68ddbf1eb3
@ -48,6 +48,7 @@
|
||||
E2EA00ED2841170100F7B269 /* UIImage+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2EA00EC2841170100F7B269 /* UIImage+Extensions.swift */; };
|
||||
E2EA00EF28420AA000F7B269 /* Data+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2EA00EE28420AA000F7B269 /* Data+Extensions.swift */; };
|
||||
E2EA00F328438E6B00F7B269 /* CapNameEntryView.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2EA00F228438E6B00F7B269 /* CapNameEntryView.swift */; };
|
||||
E2ED709A2A73D86F00067808 /* String+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = E2ED70992A73D86F00067808 /* String+Extensions.swift */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXFileReference section */
|
||||
@ -92,6 +93,7 @@
|
||||
E2EA00EC2841170100F7B269 /* UIImage+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "UIImage+Extensions.swift"; sourceTree = "<group>"; };
|
||||
E2EA00EE28420AA000F7B269 /* Data+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Data+Extensions.swift"; sourceTree = "<group>"; };
|
||||
E2EA00F228438E6B00F7B269 /* CapNameEntryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CapNameEntryView.swift; sourceTree = "<group>"; };
|
||||
E2ED70992A73D86F00067808 /* String+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+Extensions.swift"; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
@ -173,6 +175,7 @@
|
||||
E2EA00EE28420AA000F7B269 /* Data+Extensions.swift */,
|
||||
E20D105128589AAC0019BD91 /* FileManager+Extensions.swift */,
|
||||
E20D10552858CDFA0019BD91 /* View+Extensions.swift */,
|
||||
E2ED70992A73D86F00067808 /* String+Extensions.swift */,
|
||||
);
|
||||
path = Extensions;
|
||||
sourceTree = "<group>";
|
||||
@ -320,6 +323,7 @@
|
||||
E25AAC92283D8808006E9E7F /* CapData.swift in Sources */,
|
||||
E25AAC96283E14DF006E9E7F /* Database.swift in Sources */,
|
||||
E25AAC8D283D86CF006E9E7F /* Logger.swift in Sources */,
|
||||
E2ED709A2A73D86F00067808 /* String+Extensions.swift in Sources */,
|
||||
E20D105028574E190019BD91 /* CapImage.swift in Sources */,
|
||||
E2EA00ED2841170100F7B269 /* UIImage+Extensions.swift in Sources */,
|
||||
E20D105228589AAC0019BD91 /* FileManager+Extensions.swift in Sources */,
|
||||
|
@ -65,9 +65,7 @@ struct ContentView: View {
|
||||
private var selectedCapToShowImages: Cap?
|
||||
|
||||
var filteredCaps: [Cap] {
|
||||
let text = searchString
|
||||
.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
.lowercased()
|
||||
let text = searchString.clean
|
||||
guard text != "" else {
|
||||
return Array(database.caps.values)
|
||||
}
|
||||
|
@ -143,15 +143,6 @@ extension Cap: Hashable {
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: String extension
|
||||
|
||||
private extension String {
|
||||
|
||||
var clean: String {
|
||||
return lowercased().replacingOccurrences(of: "[^a-z0-9 ]", with: "", options: .regularExpression)
|
||||
}
|
||||
}
|
||||
|
||||
// MARK: Int extension
|
||||
|
||||
private extension Int {
|
||||
|
10
Caps/Extensions/String+Extensions.swift
Normal file
10
Caps/Extensions/String+Extensions.swift
Normal file
@ -0,0 +1,10 @@
|
||||
import Foundation
|
||||
|
||||
extension String {
|
||||
|
||||
var clean: String {
|
||||
lowercased()
|
||||
.replacingOccurrences(of: "[^a-z0-9 ]", with: "", options: .regularExpression)
|
||||
.trimmingCharacters(in: .whitespacesAndNewlines)
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user