I'm Using Swift 3 and firebase to create a social app where users can make posts but the thing is that I don't want the users to use curse words.
Is there a way like to replace these words when the users writes them?
Currently the users use a text view to write the things they want to post...
How can I do it in like the easiest and simple way?
I was looking for answers and I find this question Swift: how to censor/filter text entered for swear words, etc?.
With this answer code:
import Foundation
func containsSwearWord(text: String, swearWords: [String]) -> Bool {
return swearWords
.reduce(false) { $0 || text.contains($1.lowercased()) }
}
// example usage
let listOfSwearWords = ["darn", "crap", "newb"]
/* list as lower case */
let userEnteredText1 = "This darn didelo thread is a no no."
let userEnteredText2 = "This fine didelo thread is a go."
print(containsSwearWord(text: userEnteredText1, swearWords: listOfSwearWords)) // true
print(containsSwearWord(text: userEnteredText2, swearWords: listOfSwearWords)) // false
But I don't really get it. How can I implement that in my project? Where should I paste that code? Or how can I link that code to my text view? And what it´s missing on that code to work as it should be?