Search code examples
typedefeigenobjective-c++nslog

How to output values of a custom type using NSLog?


Background

I'm using VES to leverage the Kiwi point cloud viewer on iOS devices.

Error

vesVector3f v = self->mKiwiApp->cameraFocalPoint();
NSLog(@"%@",  v);

results in

Cannot pass non-POD object of type `vesVector3f` (aka 'Matrix<float, 3, 1>') to variadic function; expected type from format string was 'id'

Question

I understand that NSLog is expected to output an object of type id. How do I get NSLog to output type vesVector3f ?

Extra Details

Here are some details I found about the custom type. It appears Vector3f is a vector of 3 floats.

  • typedef Eigen::Vector3f vesVector3f;
  • EIGEN_MAKE_TYPEDEFS_ALL_SIZES(float, f)

Solution

Per trojanfoe's comment:

NSLog(@"%f, %f, %f", v(0, 0), v(1, 0), v(2, 0));

Solution

  • This looks like Objective-C++ given Eigen is a C++ library.

    You'll want to print each of the float member variables something like this:

    NSLog(@"%f, %f, %f", v(0, 0), v(1, 0), v(2, 0));
    

    I say "something like this" as I've never used Eigen.

    You can only use %@ with an Objective-C class, where you would override the description method in order for it to work to your liking.