Pergunta

I have a NSMUtableArray that I am trying to load from a Core Data store (there is valid data in the store); this is the code:

    [unsortedArray addObject:storedServices.aCustomServices1];
    [unsortedArray addObject:storedServices.aCustomServices2];

The array is defined as:

@property (nonatomic, retain) NSMutableArray *unsortedArray;

I can load the array using static data which works:

        unsortedArray = [NSMutableArray arrayWithObjects:
                     NSLocalizedString(@"Property1",nil),
                     NSLocalizedString(@"Property2",nil),nil];

The problem is although there is valid data in the CD store, the array remains empty. I have searched Google and SO but found nothing related. Why can I not load from the Core Data store?

Foi útil?

Solução

I'll take a punt that you haven't allocated unsortedArray. Try:

self.unsortedArray = [NSMutableArray array];
[self.unsortedArray addObject:storedServices.aCustomServices1];
[self.unsortedArray addObject:storedServices.aCustomServices2];

This assumes you have unsortedArray getter/setter methods that conform to normal MRR memory management practices. This is as simple as using @synthesize unsortedArray (although newer versions of clang do this for you, I'd still explicitly add it).

Note that:

self.unsortedArray = [NSMutableArray array];

Should be in your init method.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top