Objective c 这个警告在Xcode中是什么意思?

Objective c 这个警告在Xcode中是什么意思?,objective-c,xcode4.2,Objective C,Xcode4.2,我有一个从JSON API获取的资源。 JSON被解析成一个NSDictionary,在本例中称为game 我正在基于JSON的属性创建我的游戏类的一个新实例 游戏类有一个名为userRegistered的属性,该属性定义如下: // in Game.h @interface @property (nonatomic, assign) BOOL userRegistered; // elsewhere in my code I have Game *newGame = [[Game allo

我有一个从JSON API获取的资源。 JSON被解析成一个NSDictionary,在本例中称为game

我正在基于JSON的属性创建我的游戏类的一个新实例

游戏类有一个名为userRegistered的属性,该属性定义如下:

// 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);
#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
字典中用户注册的密钥将始终为1或0

Xcode警告我我有- 警告:语义问题:不兼容的整数到指针转换,将“int”传递到“BOOL*”或“signed char*”类型的参数

有人能解释一下这个问题吗?我该如何解决

使现代化 我的完整游戏类定义如下:

// 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);
#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

警告显示在newGame.userRegistered=[[game objectForKey:@user_registered]intValue]上

[game objectForKey:@user_registered]可能会给您一个NSNumber对象。您可能是想比较NSNumber对象中的整数值

([[game objectForKey:@"user_registered"] intValue] > 0)
更新以响应您的更新:

您的问题在于如何声明BOOL属性-您有一个*需要删除

@property (nonatomic, assign) BOOL *userRegistered;
应该是

@property (nonatomic, assign) BOOL userRegistered;

[game objectForKey:@user_registered]可能会给您一个NSNumber对象。您可能是想比较NSNumber对象中的整数值

([[game objectForKey:@"user_registered"] intValue] > 0)
更新以响应您的更新:

您的问题在于如何声明BOOL属性-您有一个*需要删除

@property (nonatomic, assign) BOOL *userRegistered;
应该是

@property (nonatomic, assign) BOOL userRegistered;
objectForKey函数将返回objective-c实例

([[game objectForKey:@"user_registered"] boolValue] > 0)
objectForKey函数将返回objective-c实例

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

[game Boolforky:@user\u registed]==是

[game Boolforky:@user\u registed]==是

我可以通过简单地使用布尔值来解决这个问题

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

谢谢大家的帮助

我只需使用布尔值就可以解决这个问题

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

感谢所有人的帮助

objectForKey返回一个Objective-C实例,因此肯定有问题;然而,这似乎不是警告的内容。您确定显示的是正确的行吗?用户注册的对象是布尔或整数?objectForKey返回Objective-C实例,因此确定是个问题;然而,这似乎不是警告的内容。您确定显示的行正确吗?user_registered的对象是布尔或整数?谢谢,但即使您进行了更新,它仍然会出现相同的错误:/I我认为您应该拿出好的“ol”调试器并逐步完成代码。将[game objectForKey:@user_registered]放入一个变量中,并读取它是什么类型的对象。@jurgemaister-它将作为uu NSCFNumber的一个实例出现。有什么线索吗?没关系。您可以像对待NSNumbers一样对待uu NSCFNumber对象。在Xcode的文档中,它们是类群集搜索的一部分,用于解释类群集。谢谢,但即使有了更新,它仍然会给出相同的错误:/I我认为是时候拿出好的“ol”调试器并逐步完成代码了。将[game objectForKey:@user_registered]放入一个变量中,并读取它是什么类型的对象。@jurgemaister-它将作为uu NSCFNumber的一个实例出现。有什么线索吗?没关系。您可以像对待NSNumbers一样对待uu NSCFNumber对象。在Xcode的文档中,它们是类集群搜索的一部分,用于解释类集群。游戏属于NSDictionary类型,它没有boolforky:方法。它只有objectForKey:。抱歉。我还以为是NSUserDefaultsgame属于NSDictionary类型,它没有boolForKey:method。它只有objectForKey:。抱歉。我还以为是我的错