Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/119.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ios 灵活词典_Ios_Objective C_Nsdictionary - Fatal编程技术网

Ios 灵活词典

Ios 灵活词典,ios,objective-c,nsdictionary,Ios,Objective C,Nsdictionary,我正在尝试创建一个基于xml文件的灵活字典。我在使用xmlDigester时使用了一些规则,在我尝试解析字典的值之前,一切都很顺利 上面是使用XMLdigister创建字典的对象类: @interface slideInfo : NSObject @property (nonatomic, strong) NSNumber *id; @property (nonatomic, strong) NSString *appname; @property (nonatomic, strong) NSS

我正在尝试创建一个基于xml文件的灵活字典。我在使用xmlDigester时使用了一些规则,在我尝试解析字典的值之前,一切都很顺利

上面是使用XMLdigister创建字典的对象类:

@interface slideInfo : NSObject
@property (nonatomic, strong) NSNumber *id;
@property (nonatomic, strong) NSString *appname;
@property (nonatomic, strong) NSString *marketinfos;
@property (nonatomic, strong) NSString *questionMarket;
@property (nonatomic, strong) NSString *theText;

@property (nonatomic, strong) NSMutableDictionary * mrtInfos;

-(void)addInfo:(marketInfos*)market;
-(void)questionMarket:(answerHandler*)qMarket;

@end
.m文件

@implementation slideInfo

@synthesize id, version, appname, marketinfos, questionMarket, mrtInfos, theText;

- (id)init {

    if ((self = [super init])) {
        self.mrtInfos = [NSMutableDictionary new];
    }
    return self;
}

-(void)addInfo:(marketInfos*)market
{
    NSString *key = [NSString stringWithFormat:@"%@ %@", market.name, market.image];
    [mrtInfos setObject:market forKey:key];

}

-(void)questionMarket:(answerHandler*)qMarket
{
    NSString *key = [NSString stringWithFormat:@"%@ %@ %@ %@", qMarket.name, qMarket.image, qMarket.question, qMarket.answer];
    [mrtInfos setObject:qMarket forKey:key];
    theText = qMarket.question;
    NSLog(@"Dic: %@" , theText);
}


@end
answeHandler.h

@interface answerHandler : NSObject

@property (nonatomic, strong) NSString *id;
@property (nonatomic, strong) NSString *name;
@property (nonatomic, strong) NSString *image;
@property (nonatomic, strong) NSString *question;
@property (nonatomic, strong) NSString *answer;

-(NSString *)marketString;

@end
还有.m

@implementation answerHandler

@synthesize id, name, image, question, answer;

- (id)init {
    if ((self = [super init])) {
        NSLog(@"answerHandler init");
    }
    return self;
}

-(NSString *)marketString {
    return [NSString stringWithFormat:@"%@ %@ %@ %@ %@" ,id, name, image, question, answer];
}

@end

现在我的问题是如何从字典中检索特定值?我尝试过的所有东西都返回空值。提前感谢

主要问题是您必须在字典中检索/搜索哪些数据。为什么不使用id对象作为NSDictionary中的键

-(void)addInfo:(marketInfos*)market
{
    NSString *key = [NSString stringWithFormat:@"%@ %@", market.id];
    [mrtInfos setObject:market forKey:key];

}
然后使用该id在字典中搜索

-(marketInfos*)objectFromDictionary:(NSNumber*)id
{

    return =  [mrtInfos objectForKey:id];

}

我的xml文件中有很多不同的节点。我特别想解析字典中的问题字符串