【发布时间】:2012-02-16 18:59:06
【问题描述】:
我有一个从 JSON API 获取的资源。
JSON 被解析成一个 NSDictionary,在本例中称为game。
我正在基于 JSON 的属性创建我的 Game 类的新实例。
游戏类有一个名为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);
字典中的“user_registered”键将始终为 1 或 0。
Xcode 警告我,我有 -
warning: Semantic Issue: Incompatible integer to pointer conversion passing 'int' to parameter of type 'BOOL *' (aka 'signed char *')
谁能解释一下这个问题以及我可以如何解决它?
更新
我的完整游戏类定义如下:
#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
我在这个方法中的一个 ViewController 中遇到了错误
// 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;
}
警告显示在newGame.userRegistered = [[game objectForKey:@"user_registered"] intValue];
【问题讨论】:
-
objectForKey返回一个Objective-C实例,所以肯定有问题;但是,这似乎不是警告的内容。你确定你显示的是正确的线吗? -
object For user_registered 是布尔值还是整数?
标签: objective-c xcode4.2