objective c - How to check if (id) object is null in ios? -
i have made function consume webservices , want check if (id) object null or not. doing here:
-(void)callservice:(nsstring*)request param:(nsstring*) parameters completion:(void (^)(nsarray *list, nserror *error))completionhandler { [self.manager post:request parameters:parameters success:^(nsurlsessiondatatask *task, id responseobject) { nslog(@"response object: %@", responseobject); if (![responseobject iskindofclass:[nsnull class]]) { [self methodusingjsonfromsuccessblock:responseobject]; if (completionhandler) { //nslog(@"%@", list); completionhandler(list,nil); } } else { nslog(@"nothing found"); } }failure:^(nsurlsessiondatatask *task, nserror *error) { //nslog(@"error: %@", [error description]); if (completionhandler) { completionhandler(nil,error); } }]; }
but have found on break points when (id) null has nszerodata no nsnull passes condition. using afnetworking
thanks in advance helping me out.
your responseobject
not nsnull
, nsdata
(which _nszerodata
subclass of).
so want condition:
if ([responseobject iskindofclass:[nsdata class]] && ((nsdata *)responseobject).length > 0) { // ... }
Comments
Post a Comment