Swift: How to view the values of variables displayed in Xcode's watch window?

后端 未结 1 813
生来不讨喜
生来不讨喜 2021-02-03 23:27

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 no

1条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-04 00:01

    Xcode 6 beta 4 shows values of variables of NSString and NSString? types:

    enter image description here

    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:

    enter image description here

    0 讨论(0)
提交回复
热议问题