Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Swift: Print(object) in console not showing variable properties like Objective-C for NSObjects

I'm trying to use the console debugger (LLDB) to print out some variables but quite often the output doesn't display any of the variable's properties:

p _myObject or po _myObject (neither work)

yields

(myApp.SomeEntity) $R2 = 0x00007fa4aad2fda0 {
  myApp.SomeParentEntity = {
    CoreData.NSManagedObject = {
      ObjectiveC.NSObject = {}
    }
  }
}

ditto for other NSObjects, is there a special way you have to print out NSObjects in Swift?

like image 467
Shizam Avatar asked Nov 17 '14 21:11

Shizam


People also ask

How do you print a variable in Swift?

In Swift, you can print a variable or a constant to the screen using the print() function.

How do I print to console in Objective-C?

By using printf with the appropriate parameters, we can display things this way. This is the only way I have found to work on online Objective-C sandbox environments. Show activity on this post. In Swift with Xcode you can use either print() or NSLog() .


Video Answer


2 Answers

I had the same problem with XCode 6 and Swift project.

I finally found the explanation : On the bottom left of the Debugger console your have a Menu List with 3 options :

  • All Output,
  • Debugger Output and
  • Target Output.

To see po < variableName > you have to select All output or Debugger Output.

like image 181
Claire Avatar answered Oct 06 '22 08:10

Claire


Correct way:

po _myObject

po - print object. You can read this

like image 35
user1502383 Avatar answered Oct 06 '22 09:10

user1502383