我知道 NotificationCenter 已更改,并且我已使用此链接查找如何将其更改为新的实现: NotificationCenter issue on Swift 3,但我仍然无法让我的工作!我正在使用课堂教科书在课堂上做作业,到目前为止这是我的课:
//
// ViewController.swift
// Persistence
//
// Created by Skyleguy on 10/31/16.
// Copyright © 2016 Skyleguy. All rights reserved.
//
import UIKit
class ViewController: UIViewController {
@IBOutlet var lineFields: [UITextField]!
override func viewDidLoad() {
super.viewDidLoad()
let filePath = self.dataFilePath()
if (FileManager.default.fileExists(atPath: filePath))
{
let array = NSArray(contentsOfFile: filePath) as! [String]
for i in 0 ..< array.count
{
lineFields[i].text = array[i]
}
}
let notificationName = Notification.Name("applicationWillResignActive")
NotificationCenter.default.addObserver(self, selector: #selector(Persistence.applicationWillResignActive(notification: NSNotification)), name: notificationName, object: nil)
// Do any additional setup after loading the view, typically from a nib.
}
func applicationWillResignActive(notification: NSNotification)
{
let filePath = self.dataFilePath()
let array = (self.lineFields as NSArray).value(forKey: "text") as! NSArray
array.write(toFile: filePath, atomically: true)
}
}
毕竟这一切我仍然得到一个错误:
“模块“持久性”没有名为“applicationWillResignActive”的成员”
请帮忙!