Can't see variable values in inner block

When debugging a Swift 3 program with Xcode 8.0, I am unable to see the current values of variables declared in an enclosing block. Here's a somewhat artificial eaxample that should demonstrate the problem


e.g.

class myclass {
     func a(arg: Int) -> Double
     {
          var sum = 0.0
          for i in 0 ..< 100 {
               let val = f(i, arg)
               sum += somefunc(val)
       }
       return sum
     }
}

When stepping through func a, inside the for Ioop the value of 'sum' is not available

Choosing 'Print Description of "sum"' from the popup menu gives


Printing description of sum:

(Double) sum = <variable not available>


However, the local variable 'val' is available


Am I missing some setting for the debugger in my project? I am pretty sure that this used to work in Xcode 7.x but I can no longer test that.


Regards

Bryan

Replies

One thing I’ve been bitten by previously is bogus build settings inherited from the deep past of my project (see this thread). That’s why it’s good to test this stuff with a new project, which is what I did.

Specifically, I created a new command line tool project and set

main.swift
to be the following:
func f(_ i: Int, _ j: Int) -> Int {
    return i * j
}

func somefunc(_ i: Int) -> Double {
    return Double(i * 2)
}

class myclass { 
    func a(arg: Int) -> Double 
    { 
          var sum = 0.0 
          for i in 0 ..< 100 { 
              let val = f(i, arg) 
              sum += somefunc(val) 
      } 
      return sum 
    } 
}

print(myclass().a(arg: 5))

A breakpoint at line 15 shows reasonable values for

arg
,
sum
,
i
and
val
.

Please try this yourself to see if you can replicate my results.

This was with Xcode 8.0 btw.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"

Thanks for pointing me in the right direction Quinn.


My build settings were fine (optimization levels etc) so what I did was open the .xcodeproj folder and deleted everything except for the project.pbxproj file. That is, I trashed my xcuserdata settings and project.xcworkspace


A sledgehammer approach, but it got the result I was looking for and I didn't have to rebuild the project from scratch.


Regards

Bryan

A sledgehammer approach, but it got the result I was looking for and I didn't have to rebuild the project from scratch.

I’m glad you got it working. Yay!

If you encounter problems like this again, and you don’t mind sharing, it’d be great if you made a copy of all the stuff you nuked before nuking it. That way, if said nuking resolves the problem, you can file a bug and attach all the old stuff so that our debugger engineers can investigate what went wrong.

Share and Enjoy

Quinn “The Eskimo!”
Apple Developer Relations, Developer Technical Support, Core OS/Hardware

let myEmail = "eskimo" + "1" + "@apple.com"