Using 'stringWithString:' with a literal is redundant
This question already has an answer here:
Obj-C: [NSString stringWithString:@“string”] vs. @“string”
- Figure out if there is internet or not, including wifi or data (Swift 3)
- Detecting Network Connectivity Changes using Reachability, NSNotification and Network Link Conditioner in Swift
- Send data to server whenever internet connection is available iOS
- Setting up reachability with AFNetworking 2.0
- How to get Reachability Notifications in iOS in Background when dropping Wi-Fi network?
- iOS network reachability - doesn't seem to be working
4 Solutions Collect From Internet About “Using 'stringWithString:' with a literal is redundant”
The warning is saying that you could instead easily do like this:
statusString = @"Not Reachable";
The explanation is provided in the post
Obj-C: [NSString stringWithString:@"string"] vs. @"string"
Instead of using
statusString = [NSString stringWithString: @"Not Reachable"];
please write your code like below:
statusString = @"Content-Type: Not Reachable/unknown\r\n\r\n";
warning will be removed.
You resolve these ‘warnings’ simply by declaring your strings like so:
statusString = @"";
statusString = [NSString stringWithString:@""];
I think this is a type of compiler optimization. Actually you need to assign a string to variable. You can do it directly as
myString = @"" no need to call a method and it will use additional processing time.
- Is it possible to programmatically get the identifier of a basic UIViewController from an UIViewController or Storyboard in Swift/Objective-C?
- UIStackView – Distribute views evenly from the centre
- How to Autorelease a CGImageRef?
- Iterating over an NSOrderedSet
- Find whether two Swift Arrays contain the same elements
- UILabel (CALayer) is using large amounts of virtual memory
- Facebook Login Swift iOS 10 – Nothing Works
- Adding Pins to Map using MapKit – Swift 3.0
- UITableView inside UIScrollView not receiving first tap after scrollling
- iOS CoreData – are there any disadvantages to enabling sqlite WAL / Write-Ahead Logging
- How do I detect whenever two UIImageView overlap?
- Passing object with prepareForSegue Swift
- Error: Mutating method sent to immutable object for NSMutableArray from JSON file
- NSLineBreakByWordWrapping on First Line but NSLineBreakByTruncatingTail For Second Line?
- Abstract class for Objective-C