0

In Swift, when I'm typing

var controller : GCController
// fetch some data to conbroller
NSLog("Controller: %@",controller)

NSLog prints nice

Controller: <GCController 0x1700a7680 vendorName='Remote' deviceHash=0x414e6d3d6a8c2215>

wheres vendorName is public variable in GCController, but the deviceHash is not. Can I somehow access the value? Even as plain string? From where NSLog takes the values? I tried making NSString in similar format, but it didn't give me the expected results

1 Answers1

1

NSLog is probably showing you the GCController's debugDescription property whereas print and the likes will show you the description property.

Alain T.
  • 40,517
  • 4
  • 31
  • 51
  • Is the debugDescritpion available in release build also? Or only in debug one? – Szymon Sirocki Jul 23 '16 at 08:59
  • I don't see why it wouldn't be (that should easily be verifiable by simply building in release mode). It may be a bit risky to rely on the format of the string to extract the hash out of it. Unlikely as it may sound, Apple could make changes to the framework in a future release and invalidate your string parsing logic. I believe that when there is no connected controller, that string is a bit different as well. – Alain T. Jul 23 '16 at 11:52
  • Isn't there any C#-like reflection to access this value? I've read that it reflects it's hashValue, it isn't hashtable of all values, right? It's only computing hash for comparisons? – Szymon Sirocki Jul 24 '16 at 11:21