I am trying to replace all apostrophe (') characters in a string with another character. I am running this code:
someString.replacingOccurrences(of: apost, with: "a")
I have tried to let apost equal the following:
apost = "\'"
apost = #"'"#
apost = "'"
None of them have removed the apostrophe from someString.
Please let me know if there is a way to get Swift to replace apostrophe's. Thank you.
The
replacingOccurrences(...)
method returns a new string object with the apostrophes replaced. The originalsomeString
object isn't changed by this. You need:If that's what's happened, turn more warnings on in Xcode (or look at the warnings). On my setup, this wouldn't have compiled because of the unused return value.