Can't replacing string with string

I have UITableViewCell with detailTextLabel which contains string that i want to replace with empty space(in other words to delete).It looks like this:

cell.detailTextLabel?.text = newsModel.pubDate

Now, the problem is that when i write cell.detailTextLabel?.text?.stringByReplacingOccurrencesOfString("+0000", withString: " ")

  • UITextView that expands to text using auto layout
  • Create PDF in Swift
  • The `master` repo requires CocoaPods 0.18.1 -
  • Xcode 6 GM creating archive
  • maximum number of tabs for UITabBarController without moreViewController
  • Show ratings of item in uitableview cell
  • its not working and compiler says:

    “Result of call
    ‘stringByReplacingOccurrencesOfString(_:withString:options:range:)’ is
    unused”

    Anyone can tell me the solution?
    Thanks

    Solutions Collect From Internet About “Can't replacing string with string”

    The stringByReplacingOccurencesOfString:withString: method returns a string that is the result of replacing your search string with the replacement. The warning means that you are calling a method with a non-void return value that you aren’t using.

    From the documentation (italics added by me for emphasis)

    Returns a new string in which all occurrences of a target string in the receiver are replaced by another given string.

    You can use this:

    cell.detailTextLabel?.text = newsModel.pubDate.stringByReplacingOccurrencesOfString("+0000", withString: " ")
    

    The reason you get this warning is because the method doesn’t modify the original string and returns a new string, which you don’t use. If you were to use

    cell.detailTextLabel?.text? = cell.detailTextLabel?.text?.stringByReplacingOccurrencesOfString("+0000", withString: " ")
    

    You wouldn’t get the warning because you are assigning the return value to the cell text and therefore “using” the result of the call.

    The two methods are exactly the same, except one is shorter.