-
-
Save heitortsergent/4715001 to your computer and use it in GitHub Desktop.
for(NSString* word in wordDictionary) | |
{ | |
if([word hasPrefix:appDelegate2.matchLetter] && [word isEqualToString:wordString]) | |
{ | |
return YES; | |
} | |
} | |
return NO; |
Nota: eu sei que sou chato.
SIAnswer *answer = [[SIAnswer alloc] initWithAnswer:@"rabanete"];
valid = [[answer clearAnswer] isValidAnswerforType:@"fruits"];
@StudioInvadersAnswer Class:
@property NSString *answer;
+(NSArray*)getArrayOfWordsToType:(NSString*)type{
//blah
return dictionary;
}
-(BOOL)isValidAnswerforType:(NSSTring*)type{
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"self == %@", self.answer];
NSArray *resultArray = [[SIAnswer getArrayOfWordsToType:type] fileteredArrayUsingPredicate:predicate];
if([resultArray count] > 0){
return YES;
}else{
return NO;
}
}
-(void)clearAnswer{
self.answer = [[self.answer decomposedStringWithCanonicalMapping] toLowerCase];
self.answer = [[string componentsSeparatedByCharactersInSet:[[NSCharacterSet letterCharacterSet] invertedSet]] componentsJoinedByString:@""];
}
src
http://stackoverflow.com/questions/6663792/find-value-in-array-in-objective-c
http://stackoverflow.com/questions/1231764/nsstring-convert-to-pure-alphabet-only-i-e-remove-accentspunctuation
ops, isso aqui não funciona: valid = [[answer clearAnswer] isValidAnswerforType:@"fruits"];
[answer clearAnswer] pode estar dentro do isvalidAnswerForType, anyway, foi só um rascunho rs
Além do formato de busca que foi sugerido (usando o predicate), acho que é possível otimizar a busca dividindo o dicionário em arrays. Um array para cada letra. Assim um dicionário de "n" letras com "o" palavras deixa de ter uma busca "n * o" para ter uma busca "1 * o".
E, no seu código, agilizaria muito por chamar o AppDelegate uma vez em vez de "n * o" vezes.
SIAnswer *answer = [[SIAnswer alloc] initWithAnswer:@"rabanete"];
valid = [answer isValidAnswerforType:@"fruits"]; //Eu acredito que o clear pode ficar por conta das regras do Predicate
@StudioInvadersAnswer Class:
@Property NSString *answer;
+(NSArray_)getArrayOfWordsToType:(NSString_)type{
//blah
return dictionary[matchLetterNumber]; //O matchLetterNumber é o mesmo gerado no random do seletor de letra
}
-(BOOL)isValidAnswerforType:(NSSTring*)type{
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF ==[cd] %@", self.answer]; //O [cd] do Predicate indica “case- and diacritic-insensitive like.”
NSArray *resultArray = [[SIAnswer getArrayOfWordsToType:type] fileteredArrayUsingPredicate:predicate];
if([resultArray count] > 0){
return YES;
}else{
return NO;
}
}
Esse código é só um rascunho que eu adicionei meus pensamentos às linhas descritas anteriormente...
eu sei, mas o contains não verifica a palavra toda, logo podem acertar maçã em macadâmia.
O contains foi só como exemplo. O predicate pode ser formatado para igualar os valores. O ponto mais importante que eu quis levantar foi que uma estruturação melhor dos dados pode otimizar a busca.
vc chama o app delegate só pra verificar uma letra?!!?!!?