### CocoaPods Installation Source: https://github.com/tavernari/stringcontainsoperators/blob/main/README.md Instructions for installing the StringContainsOperators library into your iOS or macOS project using CocoaPods. This involves adding the gem to your Podfile. ```ruby pod 'StringContainsOperators', '~> 1.3' ``` -------------------------------- ### Swift Package Manager Installation Source: https://github.com/tavernari/stringcontainsoperators/blob/main/README.md Instructions for adding the StringContainsOperators library to your Swift project using Swift Package Manager (SPM). This involves specifying the repository URL and version in your Package.swift file. ```swift .package(url: "https://github.com/Tavernari/StringContainsOperators.git", from: "1.3.0") ``` -------------------------------- ### Swift StringContainsOperators Complex Filtering Example Source: https://github.com/tavernari/stringcontainsoperators/blob/main/README.md Illustrates complex filtering scenarios in Swift using StringContainsOperators. It shows how to combine multiple operators (||, &&, !, ~) to create sophisticated search conditions for filtering collections of custom objects based on string properties. ```swift import StringContainsOperators struct Book { let title: String let genre: String } let books = [ Book(title: "The Lord of the Rings", genre: "fantasy"), Book(title: "Harry Potter and the Philosopher's Stone", genre: "fantasy"), Book(title: "The Hitchhiker's Guide to the Galaxy", genre: "science fiction"), Book(title: "The Shining", genre: "horror"), Book(title: "The Silence of the Lambs", genre: "thriller") ] let searchCondition = (~"Fantasy" || ~"Science Fiction") && !(~"Horror" || ~"Thriller") let filteredTitles = try books .filter { book in try book.genre.contains(searchCondition) } .map { $0.title } print(filteredTitles) // ["The Lord of the Rings", "Harry Potter and the Philosopher's Stone", "The Hitchhiker's Guide to the Galaxy"] ``` -------------------------------- ### Swift StringContainsOperators Basic Usage Source: https://github.com/tavernari/stringcontainsoperators/blob/main/README.md Demonstrates basic usage of the StringContainsOperators library in Swift, showing how to check for string containment using logical OR (||), AND (&&), NOT (!), case-insensitive/diacritic-insensitive matching (~), and regular expressions (=~). ```swift import StringContainsOperators let text = "The quick brown fox jumps over the lazy dog." // Check if text contains "quick" OR "jumps" let result1 = try text.contains("quick" || "jumps") print(result1) // true // Check if text contains "fox" AND "dog" let result2 = try text.contains("fox" && "dog") print(result2) // true // Check if text contains "fox" AND ("jumps" OR "swift") let result3 = try text.contains("fox" && ("jumps" || "swift")) print(result3) // true // Check if text contains "Brown" OR "red" case insensitively and without diacritics let result4 = try text.contains(~"Brown" || ~"red") print(result4) // true // Check if text contains "fox" AND ("Jumps" OR "swift") case insensitively and without diacritics let result5 = try text.contains(~"fox" && (~"Jumps" || ~"swift")) print(result5) // true // Check if text does NOT contain "cat" AND "bird" let result6 = try text.contains(!("cat" && "bird)") print(result6) // true // Check if text does NOT contain "brown" let result7 = try text.contains(!"brown") print(result7) // false // Check if text does NOT contain "cat" case insensitively and without diacritics let result8 = try text.contains(!~"cat") print(result8) // true // Check if text contains "quick" OR "jumps" AND "fox" using a regular expression let result9 = try text.contains(=~"(quick|jumps).*fox") print(result9) // true // Check if text contains "jumps" OR "swift" AND "fox" using a regular expression let result10 = try text.contains(=~"(jumps|swift).*fox") print(result10) // true ``` -------------------------------- ### Swift StringContainsOperators Regex Email Filtering Source: https://github.com/tavernari/stringcontainsoperators/blob/main/README.md Demonstrates using regular expressions with StringContainsOperators in Swift to filter email addresses. It shows how to define a regex pattern for specific email formats and apply it using the `contains` method for precise matching. ```swift import StringContainsOperators let emailAddresses = [ "johndoe@gmail.com", "jane_doe@hotmail.com", "johndoe123@yahoo.com", "johndoe@gmail.com.br", "johndoe123@gmail.com" ] let searchCondition = =~"^.*gmail\.com$" let filteredEmails = try emailAddresses.filter { return try $0.contains(searchCondition) } print(filteredEmails) // ["johndoe@gmail.com"] ``` -------------------------------- ### Swift Regex Operator for String Searching Source: https://github.com/tavernari/stringcontainsoperators/blob/main/README.md The `=~` operator creates a StringPredicate that performs a regular expression search for a given pattern. It simplifies the integration of regex matching into string containment checks. Note that an invalid regex pattern will throw an error. ```Swift // Swift native implementation let text = "The quick brown fox jumps over the lazy dog" let pattern = "(quick|jumps).*fox" let regex = try! NSRegularExpression(pattern: pattern, options: [.caseInsensitive]) let range = NSRange(location: 0, length: text.utf16.count) let resultNative = regex.firstMatch(in: text, options: [], range: range) != nil // StringContainsOperators implementation let resultLibrary = try text.contains(=~"(quick|jumps).*fox") ``` -------------------------------- ### Swift AND Operator for String Searching Source: https://github.com/tavernari/stringcontainsoperators/blob/main/README.md The `&&` operator performs a logical AND operation between two strings or StringPredicates. It simplifies checking if all specified strings are present within a target text, providing a concise syntax for combined search conditions. ```Swift // Swift native implementation let text = "The quick brown fox jumps over the lazy dog" let resultNative = text.contains("fox") && text.contains("dog") // StringContainsOperators implementation let resultLibrary = try text.contains("fox" && "dog") ``` -------------------------------- ### Swift Case and Diacritic Insensitive Operator Source: https://github.com/tavernari/stringcontainsoperators/blob/main/README.md The `~` operator creates a StringPredicate that performs a case-insensitive and diacritic-insensitive search for a given string. This simplifies complex comparisons that would otherwise require manual configuration of `String.CompareOptions`. ```Swift // Swift native implementation let text = "The quick brown fox" let options: String.CompareOptions = [.caseInsensitive, .diacriticInsensitive] let resultNative = text.range(of: "Brown", options: options) != nil || text.range(of: "red", options: options) != nil // StringContainsOperators implementation let resultLibrary = try text.contains(~"Brown" || ~"red") ``` -------------------------------- ### Swift Negation Operator for String Predicates Source: https://github.com/tavernari/stringcontainsoperators/blob/main/README.md The `!` operator negates a StringPredicate or a string. When used before a StringPredicate or a string, it returns a StringPredicate that represents the negation of the original search condition, simplifying the expression of 'does not contain' logic. ```Swift // Swift native implementation let text = "The quick brown fox" let resultNative = !(text.contains("cat") && text.contains("bird")) // StringContainsOperators implementation let resultLibrary = try text.contains(!("cat" && "bird")) ``` -------------------------------- ### Swift OR Operator for String Searching Source: https://github.com/tavernari/stringcontainsoperators/blob/main/README.md The `||` operator performs a logical OR operation between two strings or StringPredicates. It allows for simplified checking if any of multiple strings exist within a target text, offering a more readable alternative to chained `||` conditions. ```Swift // Swift native implementation let text = "The quick brown fox jumps over the lazy dog" let resultNative = text.contains("quick") || text.contains("jumps") // StringContainsOperators implementation let resultLibrary = try text.contains("quick" || "jumps") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.