iphone - Why might an array decoded from plist or JSON not respond to :class or :count while a programmatically created array does? -


I am facing a very troublesome problem. I have a UITableViewController that decodes a dictionary from a JSON or plist file (I have tried both) in its init method, then retrieves an array from that dictionary, later in the method table, see: numberOfRowsInSection: I, that array I am returning the count.

However, due to the reasons behind me, calling the array at that point crashes the application, though the calling count is not directly followed by the assignment in the init. In addition, if I change the initial assignment with the programmatic array created (NSArray initWithObjects), then it works fine.

JSON decoding init:

  NSString * jsonpath = [[NSBundle main bundle] Pathfoser resource: @ "Categories" type: @ "Jason"]; SBJSON * JasonPerser = [SBJSEN NEW]; NSDictionary * dict = [jsonParser ObjectWithString: [NSString stringWithContentsOfFile: jsonPath encoding: NSUTF8StringEncoding Error: Zero]]; Categories = [Dick ObjectForcae: @ "Content Content"]; // Outputs correctly counting NSLog (@ "Count:% @", [NSNumber NumberAttah: [Counts count]]); Programmatic Init:  
  categories = [[NSARLAOC] initWithObjects: [[NSDictionary alloc] initWithObjectsAndKeys: @ "junk", @ "title"]] ; // Outputs correctly counting NSLog (@ "Count:% @", [NSNumber NumberAttah: [Counts count]]);  

The UITableViewController number of the line method:

  // The program correctly decides if the output crashes, then json / plist NSLog ( @ "Count:% @", [NSNumber NumberAttah: [Counts count]]);  

I have tried the "categories" variable as an ivar, a property-ivar, and a square variable, as a destiny.

Thank you for your help!

I think the JSON is not familiar with the parser, but if it is following the coco conventions , Then the object stroke means an autoreleased object back, it will be removed on the next recurrence through the Runlop, unless you maintain it. When coco denotes collection classes, they release everything in which they are contained, so the categories will also be released. This is the reason that it works for the first time, but not later in the program.

The reason it works by building a property is that the synthetic setter retains the created categories (assuming you maintain the parameter that you think you did) , So it will not be released. This is the right solution, good work. Calling made on categories will also be working.

The cocoa conference is that if any method name starts with "Alok" or "Copy", or "new", then the item returns 1, and you have to issue it Are responsible. Otherwise, the returned object has been retained in the number of zero (it has been autorescaled), and it will be removed on the next move through the raillope, unless you maintain it (in this case you will not later Take responsibility to issue).

I recommend reading this:

Edit: The reason is because [[NSArray alloc] initWithObjects ...] is being used because "alloc" The returned array has not been autoriated, and it is also when you access it.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

Visual Studio 2005: How to speed up builds when a VSMDI is open? -

booting ubuntu from usb using virtualbox -