How do i go about seeing if my integer is in an array of integers…
eg i want to know if 7 is in an array of [ 1 3 4 5 6 7 8]
any ideas?
Thanks
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There are several ways to do this depending on factors such as size of the array – how often you need to search, how often you need to add to the array etc. In general this is a computer science problem.
More specifically I’d guess there are three options likely to best fit your needs.
containsObject:on theNSArraywill do this for you. Simple and probably fastest for small array sizes.containsObject:to check for existence