2010-09-30 5 views
1

Heres my Array.Comment concatter une chaîne + int et la faire correspondre à un élément dans un NSArray?

NSArray *arrayData = [[NSArray alloc] initWithObjects:@"1 days", @"7 days", 
    @"14 days", @"28 days", @"1 months", @"2 months", 
    @"3 months", @"4 months", @"6 months", @"1 years", 
    @"2 years", @"once", nil]; 

Utilise mon NSString et mon entier.

int interval = 2; 
NSString *itype = @"years"; 

J'ai besoin de se joindre à l'entier + un espace + le NSString et correspondre avec l'élément du tableau et obtenir le numéro d'index du tableau afin que je puisse prendre le même indice d'un autre NSArray.

Comment faire?

Répondre

5

Pour se joindre à la chaîne et entier:

NSString* yearString = [NSString stringWithFormat:@"%d %@", interval, itype]; 

Et pour rechercher le tableau:

[array indexOfObject:yearString]; 
+0

OK, wheres le numéro d'index? – Jules

+0

int indexOfObject = [array indexOfObject: yearString]; // :) – Jules

Questions connexes