Can't replacing string with string
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: " ")
its not working and compiler says:
“Result of call
Anyone can tell me the solution?
- Retrying an asynchronous operation using ReactiveCocoa
- Why doesn't Swift provide classes memberwise initializers?
- Send HTTP Requests in Background Mode (iOS) Periodically
- How to save cookies in shared preferences in iOS?
- How to sort NSString like iTunes sorting?
- jQuery Mobile prevent scroll-to-top before page transition?
Solutions Collect From Internet About “Can't replacing string with string”
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.
- CAGradientLayer diagonal gradient
- How can I change the UISearchBar search text color?
- iOS :How to get Facebook Album Photo's Picker
- linking against dylib built for MacOSX file '/usr/lib/libSystem.B.dylib' for architecture i386
- Delete last character in Swift 3
- XCode and updated SVN
- Understanding Swift argument notation in functions like tableView
- Singleton or Class methods
- Swift structs to NSData and back
- Facebook iOS SDK – Strange Effects in Writing to Status
- How to Navigate from one View Controller to another using Swift
- Proper way to find the closest beacon
- Send programmatically SMS on jailbreak device
- Upload Photo / File with JSON and custom headers via Swift 3 and Alamofire 4 | iOS | Swift
- XCODE 6 (6A313) Compile Error using Outlets