Simple question - how can you view the values of variables in Xcode's watch window when using Swift?
Here's an example, see how mdn has the value 2067134273 yet its not possible to view that in the watch window (ObjectiveC.NSObject doesn't expand to anything).
I thought this might be due to the fact that its an optional, however its not that straightforward because look at the display of onss which is displayed as "Optional NSString", its possible to view that and its an NSString?, while nss which is a non optional NSString doesn't have its value displayed.
Here's their declarations:
var nss:NSString = "NSString"
var ss = "Swift string"
var onss:NSString? = "Optional NSString"
So when debugging with Xcode how can the values of mdn and nss be viewed, and preferably be made to be displayed automatically without having to use the console?
Xcode 6 beta 4 shows values of variables of NSString
and NSString?
types:
Nevertheless if you may need to see details for some other type even from some third-party framework that you cannot alter then you can implement debugQuickLookObject
method and return custom description. In case of third-party lib you should wrap it in extension. For NSString
it will be:
extension NSString {
func debugQuickLookObject() -> AnyObject {
return self
// return "Here is debug value: \(self)"
}
}
To preview it, just select the item in watch window and hit spacebar
:
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With