Search code examples
iosstream-operators

Is there an output stream class for IOS I could use to print class data like qDebug in QT?


In QT to many classes have stream << operators to print useful information about class members. For example I can print QImage or QRect size like this:

QImage image(500, 100, QImage::Format_RGBA8888_Premultiplied);
qDebug() << "image: " << image;

output: image: QImage(QSize(500, 100) )

QRect rect(3, 4, 100, 50);
qDebug() << "rect: " << rect;

output: rect: QRect(3,4 100x50)

I find this pretty useful as you don't have to type every single class member to print it.

I am new to IOS coding. Is there any simple way to to the same thing for basic classes like CGRect, that I'm missing?


Solution

  • You can use standard library:

    NSLog(@"%@", NSStringFromCGRect(view.rect));
    

    or try better solution - is DDLog library, it can turn all logs output for example for release build, in this case use:

    DDLogInfo(@"%@", NSStringFromCGRect(view.rect));
    

    or

    DDLogWarn(@"%@", NSStringFromCGRect(view.rect));
    

    images to can be printed:

    DDLogWarn(@"%@", image);