Работа над учебником, который немного устарел и нуждается в помощи, чтобы выяснить, как инициализировать без необязательных типов
var resultsController: NSFetchedResultsController<Todo>!
let coreDataStack = CoreDataStack()
override func viewDidLoad() {
super.viewDidLoad()
//Request
let request: NSFetchRequest<Todo> = Todo.fetchRequest()
let sortDesriptors = NSSortDescriptor(key: "date", ascending: true)
//Init
request.sortDescriptors = [sortDesriptors]
resultsController = NSFetchedResultsController(
fetchRequest: request,
managedObjectContext: coreDataStack.managedContext,
sectionNameKeyPath: nil,
cacheName: nil)
resultsController.delegate = self
//Fetch
do {
try resultsController.performFetch()
} catch {
print("Perfom fetch error: \(error)")
}
}
var managedContext: NSManagedObjectContext!
var todo = Todo?
if let todo = todo { <--- same issue here
textView.text = todo.title
textView.text = todo.title
segmentedControl.selectedSegmentIndex = Int(todo.priority)
if let todo = todo { //<-- need help here.
todo.title = title
todo.priority = Int16(segmentedControl.selectedSegmentIndex)
} else {
let todo = Todo(context: managedContext)
todo.title = title
todo.priority = Int16(segmentedControl.selectedSegmentIndex)
todo.date = Date()
}
Инициализатор для условного связывания должен иметь необязательный тип, а не 'Todo? .Type'
продолжайте получать это сообщение об ошибке