Search This Blog

Showing posts with label check array length. Show all posts
Showing posts with label check array length. Show all posts

Tuesday, 18 March 2014

How null,nill, and lenght 0 object can be checked ???

The simplest way to check NSNull value , nill value, and lenght =0 of object:

static inline BOOL IsEmpty(id object)
{
    return object == nil
    || ([object respondsToSelector:@selector(length)]
        && [(NSData *) object length] == 0)
    || ([object respondsToSelector:@selector(count)]
        && [(NSArray *) object count] == 0)
    || ([object respondsToSelector:@selector(count)]
        && object == nil)
    || ([object respondsToSelector:@selector(count)]
        && [ object isKindOfClass:[NSNull class]]);
    

}


How to call inline function:

 NSString *str =nil;
    
    if(!(IsEmpty(str)))
    {
        NSLog(@"The object is not null, nill,");

    }