Sunday 15 March 2015

iphone - objectForKey stringValue crashing my app? -


I have a class that I use to set up an object in the array. In this class I have a custom "initWithDictionary", where I parse a JSON dictionary However, as I am running in NSNull To get around it, I set up a class that handles exceptions, so when a string is NSNull , it should be sent to @ "" Is replaced by Or for -1 integers

This is my NullExtensions class:

  @interface NSNull (valueExtensions) - (int) intValue; - (NSString *) stringValue; @end @implementation NSNull (Value Extension) - (Int) Interview {Return -1; } - (NSString *) stringValue {return @ ""; } @end  

However, in my initWithDictionary method, the following code crashes my app:

  self.bookTitle = [[parsedDictionary objectForKey: @ "Book_top"] string value];  

Perceived dictionary does not work with NSNull or a valid string regardless of the object only if I do the following (and the string is not empty):

  self.bookTitle = [parsedDictionary objectForKey: @ "book_title"];  

Is stringValue wrong in this case? And if so, how do I use it correctly for setting up the correct NSNull replacement? Instead of creating categories on

Thx

NSNull , For which you also need to add the same category to NSString (This is the reason that accidents do not respond to string strings because the actual strings) - instead of a support category on NSDictionary Try making use of " stringForKey " code uses Johan and a NSString , maybe all other types as empty string Chci way should be mapped.


No comments:

Post a Comment