How to find size of object in iOS?

433 Views Asked by At

I am working on a app in which I have to find size of web service response and response type is id. Please suggest me a suitable answer to fetch size of id object.

Here in this code I have to find the size of value.

-(void)getOneTimeWebpayCardsHandler:(id) value
{

YPGetOneTimeWebpayCardsResponse* result = (YPGetOneTimeWebpayCardsResponse*)value;

}
2

There are 2 best solutions below

0
On

If it is just a simple object without any extra internal allocations, this should work:

#import <malloc/malloc.h>

NSLog(@"response size: %zd", malloc_size(response));
0
On

If I understand your question correctly:

You might check the HTTP headers of the response:

Content-Type: The value of this header specifies the MIME type, e.g. application/json and possibly additional parameters, like "charset", e.g. application/json; charset=utf-8 of the response data.

Content-Length: The value of this header specifies the length in bytes of the response data.

See also NSHTTPURLResponse and NSURLResponse in the original documentation.