NotificationCenterが変更されたことを理解していますが、このリンクを使用して新しい実装に変更する方法を調べました:NotificationCenter issue on Swift 3、しかし私はまだ仕事ができません!私はクラスのテキストブックを使用して私のクラスからの割り当てをやっているし、これはこれまでのところ、私のクラスである。このすべての後NotificationCenterを使用して迅速にObserverを追加する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' "
お手数です!
次にあなたは間違って理解し「私は通知センターが変更されたことを理解して」。それは全く変わっていない。 – matt