bodacious
bodacious

Reputation: 6695

What does this warning mean in Xcode?

I have a resource which is fetched from a JSON API. The JSON is parsed into a NSDictionary which, in this case is called game.

I'm creating a new instance of my Game class based on the attributes from the JSON.

Game class has a property called userRegistered which is defined as follows:

// in Game.h
@interface
@property (nonatomic, assign) BOOL userRegistered;


// elsewhere in my code I have
Game *newGame = [[Game alloc] init];
newGame.userRegistered = ([game objectForKey:@"user_registered"] > 0);

The "user_registered" key in the dictionary will always be either 1 or 0.

Xcode warns me the I have - warning: Semantic Issue: Incompatible integer to pointer conversion passing 'int' to parameter of type 'BOOL *' (aka 'signed char *')

Can someone please explain the issue and how I might resolve it?

Update

My full game class is defined as follows:

#import <Foundation/Foundation.h>

@interface Game : NSObject

@property (nonatomic, copy) NSString *name;
@property (nonatomic, copy) NSString *photoURL;
@property (nonatomic, copy) NSString *gameURL;
@property (nonatomic, assign) BOOL *userRegistered;

@end

// Game.m
#import "Game.h"

@implementation Game

@synthesize name = _name;
@synthesize partnerName = _partnerName;
@synthesize photoURL = _photoURL;
@synthesize gameURL = _gameURL;
@synthesize userRegistered = _userRegistered;

@end

I'm getting the error in one of my ViewControllers in this method

     // api_response.body has just been set to an __NSCFArray containing 
     // NSDictionaries by AFNetworking
     NSDictionary *game;
     Game *newGame;
     for (game in api_response.body){
         newGame = [[Game alloc] init];

         NSLog(@"Creating a new game");
         // set attributes for new game instance
         newGame.name = [game objectForKey:@"name"];
         newGame.photoURL = [game objectForKey:@"photoURL"];
         // user registered is either 0 (false) or 1 (true)
         newGame.userRegistered = [[game objectForKey:@"user_registered"] intValue];

         // add the game instance to the appropriate array
         [self addGameToGamesArray:newGame];
         newGame = nil;
     }

The warning shows over newGame.userRegistered = [[game objectForKey:@"user_registered"] intValue];

Upvotes: 1

Views: 1892

Answers (4)

bodacious
bodacious

Reputation: 6695

I was able to solve this issue by simply using boolValue

game.userRegistered = [[json objectForKey:@"user_registered"] boolValue];

Thanks all for the help

Upvotes: 1

commanda
commanda

Reputation: 4881

[game objectForKey:@"user_registered"] is likely giving you an NSNumber object. You probably mean instead to compare the integer value inside that NSNumber object.

([[game objectForKey:@"user_registered"] intValue] > 0)

UPDATE in response to your update:

Your problem is with how you're declaring your BOOL property - you have a * that you need to remove.

@property (nonatomic, assign) BOOL *userRegistered;

should be

@property (nonatomic, assign) BOOL userRegistered;

Upvotes: 4

Vladimir Stazhilov
Vladimir Stazhilov

Reputation: 1954

([game boolForKey:@"user_registered"]==YES)

Upvotes: 0

Parag Bafna
Parag Bafna

Reputation: 22930

objectForKey function will return an objective-c instance.

([[game objectForKey:@"user_registered"] boolValue] > 0)

Upvotes: 0

Related Questions