4

NSDictionary will not complete

 2 years ago
source link: https://www.codesd.com/item/nsdictionary-will-not-complete.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

NSDictionary will not complete

advertisements

I have the following piece of code.

-(NSDictionary *)getPlayers
{

    NSManagedObjectContext *context = self.genkDatabase.managedObjectContext;

    NSFetchRequest *fetchRequest = [[NSFetchRequest alloc] init];
    NSEntityDescription *entity = [NSEntityDescription entityForName:@"Team"
                                              inManagedObjectContext:context];
    fetchRequest.predicate = [NSPredicate predicateWithFormat:@"position ==[c] %@", @"Doelman"];
    [fetchRequest setEntity:entity];

    NSError *error;
    NSArray *fetchedObjects = [context executeFetchRequest:fetchRequest error:&error];
    if (fetchedObjects == nil) {
        // Handle the error.
    }else

        for (Team *info in fetchedObjects) {

            [_photos setObject:info.image  forKey:@"player_imgUrl"];
            [_photos setObject:info.name forKey:@"player_name"];

        }
    NSLog(@"%@",_photos);
    return _photos;

But for some reason or another my NSLog always gives (null) back. But when I do this

[_photos setObject:info.image  forKey:@"player_imgUrl"];
            [_photos setObject:info.name forKey:@"player_name"];

            NSLog(@"name: %@",info.name );
            NSLog(@"url: %@",info.image );

It gives the right data back.

Can somebody help?

Kind regards.


Make sure you have instantiated your _photos dictionary somewhere with the following line of code:

_photos = [[NSMutableDictionary alloc] init];

Just defining it as an instance variable or a property is not enough.


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK