Reputation: 705
I am new to objective C. I have created an NSString array by the following way:
static NSString* fontSizeName[] =
{
@"14",
@"18",
@"22",
@"26",
@"30",
@"34",
};
Now, i have the value, "26", how can i get the index of it in fontSizeName[]?
Thanks for input.
Upvotes: 0
Views: 2632
Reputation: 27017
Use the indexOfObject
method:
index = [fontSizeName indexOfObject:@"26"];
Upvotes: 2
Reputation: 410552
NSString *val = @"26"; // Get this from somewhere
int i;
int idx = -1;
for (i = 0; i < 6; i++) {
if ([fontSizeName isEqualToString:val]) {
idx = i;
break;
}
}
Upvotes: 1