I would like to know if it is possible to use the description function in the Cocoa framework to log the contents of a struct. For example:
typedef struct {float a,b,c;}list;
list testlist = {1.0,2.5,3.9};
NSLog(@"%@",testlist); //--> 1.0,2.5,3.9
No. The
descriptionmessage is a method found in theNSObjectprotocol, so by definition, must be an object. There is, however, a more convenient way of log debugging, using aLOG_EXPR()macro. This will take objects and structs:LOG_EXPR(testlist);Which would output:
This code can be found here.