I am writing a simple app with a form in Swift, I had the app written in Objective-C to populate an e-Mail with data from text fields in a view, I used the following code to do this:
NSString *messageBody = [NSString stringWithFormat:@"Name: %@ \nDate: %@", NameField.text, DateField.text];
I am trying to achieve the same thing in Swift, I have the following so far:
let messageBody = NSString(format: "Name: %@ \nDate: %@", NameField, DateField)
I am looking for swifts equivalent to "%@"
to make the app look to the format of the string to find the data to place after "Name:"
.
In Swift you use \(some_printable_object_or_string)
like
let string = "Name: \(NameField) \nDate: \(DateField)"
Or you can use ObjectiveC-style formatting
let string = String(format: "Name: %@ \nDate: %@", NameField, DateField)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With