Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy is my NSArray turning into an NSSet?
    primarykey
    data
    text
    <p>In Objective-C, using core data, I was fetching entities and they were returned as NSArrays. I realized that I was fetching too often and I could make use of the entity's return values, for example: Customer entity has many Invoices, Invoices have many ItemSolds. Here is some code I'm using:</p> <pre><code>NSError *error = nil; // fetch all customers NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init]; NSEntityDescription *entity = [NSEntityDescription entityForName:@"Customer" inManagedObjectContext:managedObjectContext]; [fetchRequest setEntity:entity]; self.fetchedCustomers = [managedObjectContext executeFetchRequest:fetchRequest error:&amp;error]; if (fetchedCustomers == nil) { NSLog(@"ERROR"); } [fetchRequest release]; // end of customer fetch </code></pre> <p>This is the simple fetch request, and fetchedCustomers is set as an NSArray property. I then use it's functions :</p> <p><code>self.fetchedInvoices = [[customerToView valueForKey:@"invoices"] allObjects];</code></p> <p>This works, and I'm able to display invoice numbers and dates into a table properly. However I then go on to use :</p> <pre><code>self.fetchedObjects = [[fetchedInvoices valueForKey:@"itemsSold"] allObjects]; </code></pre> <p>Later, when I try to add totals I do the following:</p> <pre><code> double price = [[[fetchedObjects objectAtIndex:i] valueForKey:@"Price"] doubleValue]; </code></pre> <p>And I get the following error:</p> <pre><code>-[__NSCFSet doubleValue]: unrecognized selector sent to instance 0x10228f730 </code></pre> <p>Why is there an NSSet involved here at all? When I fetched the invoices and items using predicates, I didn't have any problems, but it seemed really inefficient. I would much rather figure out what's going wrong here. Any help would be appreciated, thanks.</p> <p>Extra info:</p> <p>Areas of interest:</p> <pre><code>@interface Invoice : NSManagedObject { @private } @property (nonatomic, retain) NSSet *itemsSold; @end @interface Invoice (CoreDataGeneratedAccessors) - (void)addItemsSoldObject:(ItemSold *)value; - (void)removeItemsSoldObject:(ItemSold *)value; - (void)addItemsSold:(NSSet *)values; - (void)removeItemsSold:(NSSet *)values; @end </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload