Xcode warning: implicit declaration of NSStringFromRect


I have a quick question. I get xcode warning: implicit declaration of function ‘NSStringFromRect’ while building an iPad application. I want to NSLog CGRect values of frames in subviews. I was told to import ‘stdio.h’ for whatever reason but it did not help. Is there an gcc/xcode pragma to suppress warnings? Frustrating though.


In your iPhone/iPad application use NSStringFromCGRect function instead of NSStringFromRect. You do not need to import ‘stdio.h’ but ‘Foundation/Foundation.h’. Why?

In objective-c, when you are linking against the iPhone SDK, there is no declaration for NSStringFromRect, or for NSPoint or NSStringFromPoint. I assume that UIKit uses the Core Graphics structs CGPoint, CGSize and CGRect, so the equivalent function would be NSStringFromCGRect, or NSStringFromCGPoint…

It is expected to be compiled without warnings:

    #import <Foundation/Foundation.h>
    // .......
    // NSLog subviews
    for (UIView *subview in views)
        NSLog( @"Subview=%@ Frame=%@", NSStringFromClass([subview class]), NSStringFromCGRect(subview.frame) );