开发者

How do I concat a string + int and match it to an item in an NSArray?

开发者 https://www.devze.com 2023-01-18 09:10 出处:网络
Heres my Array. NSArray *arrayData = [[NSArray a开发者_开发百科lloc] initWithObjects:@\"1 days\", @\"7 days\",

Heres my Array.

NSArray *arrayData = [[NSArray a开发者_开发百科lloc] 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];  

Heres my NSString and my integer.

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

I need to join both the integer + a space + the NSString and match it with the item in the array and get the index number of the array so I can pick the same index from another NSArray.

How do i do this ?


To join the string and integer:

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

And to search the array:

[array indexOfObject:yearString];
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号