In Swift
, say for example I have a struct
for this model
:
struct Message {
var message: String = ""
var timestamp: String = ""
var id: String = ""
}
And I would be instantiating multiple Messages
using this struct
from a database, and then populate a TableView
with them.
Would it be best practice to using optionals instead of setting these variables with empty strings like such?
struct Message {
var message: String?
var timestamp: String?
var id: String?
}
Would it be more efficient to basically setting the variables to nil
vs an empty string
? Does nil
take less memory vs empty string
?