Basically what´s the difference between String()
and ""
var x = "Test"
x = String()
x = ""
Will there be any difference between these two lines above?
Basically what´s the difference between String()
and ""
var x = "Test"
x = String()
x = ""
Will there be any difference between these two lines above?
According to the Apple documentation, the strings are equivalent:
Initializing an Empty String
To create an empty String value as the starting point for building a longer string, either assign an empty string literal to a variable, or initialize a new String instance with initializer syntax:
var emptyString = "" // empty string literal var anotherEmptyString = String() // initializer syntax
My understanding is when you set a String literal
var aString = ""
will at some point be converted, at least functionally, to
var aString: String = String("")
So you're technically adding a meaningless amount of work at compile time, but nothing that should matter in pretty much any circumstance.