현재 사용자가 NSDictionnary에서 일부 매개 변수를 정의하는 프로젝트에서 작업하고 있는데, 일부 개체를 설정하는 데 사용하고 있습니다. 예를 들어 매개 변수 param1 = xxx, param2 = yyy, gain = 3.5 ...를 사용하여 Sound 객체를 만들도록 요청할 수 있습니다. 매개 변수 speed = 10, active = YES, name = zzz ...set ivars from NSDictionnary
인 Enemi 객체 그때 내 클래스의 인스턴스를,이 사전도에서 자동으로 인스턴스 변수를 설정하려는
{
active = NO;
looping = YES;
soundList = "FINAL_PSS_imoverhere_all";
speed = 100.0;
}. 실제로이 매개 변수가 있는지 확인하기 위해 일부 코드를 작성했지만 실제로 매개 변수 값을 설정하는 데 문제가 있습니다. 특히 매개 변수가 아닌 경우 (float 또는 bool).
여기에 내가 지금까지 뭘하는지 : 당신이 볼 수 있듯이
//aKey is the name of the ivar
for (NSString *aKey in [properties allKeys]){
//create the name of the setter function from the key (parameter -> setParameter)
NSString *setterName = [aKey stringByReplacingCharactersInRange:NSMakeRange(0,1) withString:[[aKey substringToIndex:1] uppercaseString]];
setterName = [NSString stringWithFormat:@"set%@:",setterName];
SEL setterSelector = NSSelectorFromString(setterName);
//Check if the parameter exists
if ([pge_object respondsToSelector:setterSelector]){
//TODO : automatically set the parameter
}
else{
[[PSMessagesChecker sharedInstance]logMessage:[NSString stringWithFormat:@"Cannot find %@ on %@", aKey, [dict objectForKey:@"type"]] inColor:@"red"];
NSLog(@"Cannot find %@ on %@", aKey, [dict objectForKey:@"type"]);
}
}
}
, 난이 매개 변수는 객체에 존재하는 것으로 나타났습니다 일단 어떻게 해야할지 모르겠어요. "performSelector ... withObject ..."를 사용하려고했지만 내 문제는 일부 매개 변수가 비 객체 (float 또는 bool)입니다. 또한 setter를 사용하여 매개 변수의 클래스를 가져 오려고 시도했지만, 하지만 도움이되지 않았다.
이사람이 그런 일을 할 관리 했습니까?
'setValuesForKeysWithDictionary :'! –
오! 나는 그 하나를 놓쳤다! 감사합니다. –