diff --git a/Caps.xcodeproj/project.pbxproj b/Caps.xcodeproj/project.pbxproj index 972b495..938af63 100644 --- a/Caps.xcodeproj/project.pbxproj +++ b/Caps.xcodeproj/project.pbxproj @@ -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 = ""; }; E2EA00EE28420AA000F7B269 /* Data+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Data+Extensions.swift"; sourceTree = ""; }; E2EA00F228438E6B00F7B269 /* CapNameEntryView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CapNameEntryView.swift; sourceTree = ""; }; + E2ED70992A73D86F00067808 /* String+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "String+Extensions.swift"; sourceTree = ""; }; /* 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 = ""; @@ -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 */, diff --git a/Caps/ContentView.swift b/Caps/ContentView.swift index 6cd759f..d4e3f3a 100644 --- a/Caps/ContentView.swift +++ b/Caps/ContentView.swift @@ -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) } diff --git a/Caps/Data/Cap.swift b/Caps/Data/Cap.swift index cdc514a..a8aa6b3 100644 --- a/Caps/Data/Cap.swift +++ b/Caps/Data/Cap.swift @@ -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 { diff --git a/Caps/Extensions/String+Extensions.swift b/Caps/Extensions/String+Extensions.swift new file mode 100644 index 0000000..acc7bcd --- /dev/null +++ b/Caps/Extensions/String+Extensions.swift @@ -0,0 +1,10 @@ +import Foundation + +extension String { + + var clean: String { + lowercased() + .replacingOccurrences(of: "[^a-z0-9 ]", with: "", options: .regularExpression) + .trimmingCharacters(in: .whitespacesAndNewlines) + } +}