开发者

Multiple Arrays [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 12 years ago.

Is there a way to access/store multiple arrays or data which could be compared against and return a value to ensure a program is faster?

I will have two variables with multiple possibilities I want to compare these two variables to all the possibilities and 开发者_如何学Goreturn a value but that will slow down the speed of the app is there a way to do it faster?


Sounds like you want to check for existence of an object within a set. Sets have a very fast look-up time but do not retain the order of the objects. They are particularly useful for checking whether a value is within a particular set of values. For example, the following snippet acquires a string of text from the user and ensures that it is either @"Abc", @"Def", or @"Ghi". This trivial case involves only three elements but of course you can easily add more.

NSSet *possibleValues = [NSSet setWithObjects:@"Abc", @"Def", @"Ghi", nil];

NSString *userProvidedInput = /* obtain from user somehow */;

if ([possibleValues containsObject:userProvidedInput])
{
    NSLog(@"The user provided correct input!");
}

NSSet objects can contain any NSObject subclass, including NSString, NSNumber, etc. If you have a lot of elements in the set, consider storing them in a plist file (use an array), and use something like:

[NSSet setWithArray:[NSArray arrayWithContentsOfFile:@"some.plist"]];
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜