Use of unresolved identifier 'self'

This error message appears in App/Delegate.swift shown below:


func applicationShouldTerminate(_ sender: NSApplication) -> NSApplication.TerminateReply {

// Save changes in the application's managed object context before the application terminates.

let context = persistentContainer.viewContext

if !context.commitEditing() {

NSLog("\(NSStringFromClass(type(of: self))) unable to commit editing to terminate") <-- ERROR OCCURS HERE

return .terminateCancel

}

Why am I getting this error, and how do I correct it?

Is it OSX App ?

Which error do you get ?


I have tried this, which compiles (of course, import CoreData) ; but only available in OSX 10.12+


    func applicationShouldTerminate(_ sender: NSApplication) -> NSApplication.TerminateReply {
        if #available(OSX 10.12, *) {
            let persistentContainer = NSPersistentContainer(name: "whateverYouLikeHere")
            // Save changes in the application's managed object context before the application terminates.
            let context = persistentContainer.viewContext
           
            if !context.commitEditing() {
                NSLog("\(NSStringFromClass(type(of: self))) unable to commit editing to terminate") // <-- ERROR OCCURS HERE
                return .terminateCancel
            }
        } else {
            // Fallback on earlier versions
        }
        return .terminateCancel // return what you need to return
    }

Claude, I'm sorry I forgot to include the error message which is: Use of unresolved identifier 'modelURL'


Yes, this is an OSX app, and whenever I've been notified of an update, I always apply it!


I'm not sure where to insert the func you provided me, but I'll play around a bit until I get it tow work.


Additionally, when I inserted your code I got an error on 'self' in the NSLog statement.


Thanks for your help,

Terry

I included this in AppDelegate, and that just compiled fine for me.


Just in case : how and where did you define persistentContainer ?


I do not see 'modelURL' in your NSLog. Bizarre !

Is that solved ?

Use of unresolved identifier 'self'
 
 
Q