I'm following a tutorial that was written in some earlier version of Swift, that teaches me how to read/write a .txt file in Swift3. Xcode has been doing a good job so far of letting me know when I'm using old syntax, and changing it for me to the latest syntax. However, I'm coming across something that works in an older version of Swift, but not the current one.
class ViewController: UIViewController {
// MARK: Properties
@IBOutlet weak var monthToEditTextField: UITextField!
@IBOutlet weak var bedTimeTextField: UITextField!
@IBOutlet weak var wakeTimeTextField: UITextField!
@IBOutlet weak var theLabel: UILabel!
@IBAction func saveButton(_ sender: UIButton)
{
var theMonth = monthToEditTextField.text
var bedTime = bedTimeTextField.text
var wakeTime = wakeTimeTextField.text
var stringForTXTFile = "The user's info is: \(theMonth), \(bedTime), \(wakeTime)"
let fileManager = FileManager.default
if (!fileManager.fileExists(atPath: filePath))
{
var writeError: NSError?
let fileToBeWritten = stringForTXTFile.write(toFile: // This is where the problem is
}
}
When I type
stringForTXTFile.write
I get this error box
What do I need to do in order to use the "write" property?