What is causing myself to be undefined in my AppDelegate?

I've been working on an application for a few weeks, then did a big refactoring and somehow broke my application's delegate.

If I put a breakpoint at applicationDidFinishLaunchingWithOptions

and type p self

, I see the following error:

error: <EXPR>:1:1: error: use of unresolved identifier 'self'
self
^

      

If I put a breakpoint at applicationDidBecomeActive

and type p self

, then I won't get any errors, and the kernel itself will be correctly defined.

If I start with a new project I don't have this problem.

Mine AppDelegate.swift

looks like this:

import UIKit
import CoreLocation

@UIApplicationMain
class AppDelegate: UIResponder, UIApplicationDelegate {

    var window: UIWindow?

    func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {

         return true
    }

}

      

+3


source to share


2 answers


So, I tried it in Xcode 7 and I can p self

successfully.

Then I switched to Xcode 6 and p self

it works again.



This pretty much confirms the bug, and the workaround is to run your project in Xcode 7 without updating your syntax (I had to temporarily comment out some code that won't compile in Xcode 7) and then switch back to Xcode 6.

0


source


"self" is more difficult for the expression evaluator than you might naively think. It cannot just tell the compiler about the variable, it must convince the compiler that the code in the expression is run in the context of a method for any class "I", and then the compiler will infer the presence of itself, Otherwise things like bare access to ivar and method call won't work.



Originally there was a problem with this little two-step, but they had to be sorted by Xcode 7. If you see this problem in Xcode 7, please post bugs and we'll see.

+1


source







All Articles