Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6007789
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T01:43:57+00:00 2026-05-23T01:43:57+00:00

Okay, so, I’m doing a simple lookup. I have an array of NSString objects

  • 0

Okay, so, I’m doing a simple lookup. I have an array of NSString objects and a string to search for in the array’s elements.

It all seems to work up until I try to add a match to a new mutable array made to hold the search results. The stringHolder variable gets the string, and resultsCollectorArray even get the right number of new elements, but each element is empty and “out of range”. Here’s the method:

@implementation NSArray (checkForString)

-(NSMutableArray *) checkForString: (NSString *) matchSought
{
    long unsigned numberofArrayElements;
    long unsigned loop = 0;
    NSRange searchResults;
    NSMutableArray * resultCollectorArray = [[NSMutableSet alloc] init];
    id stringHolder;

    numberofArrayElements = [self count];

    while (loop < numberofArrayElements) {
        searchResults.length = 0;
        searchResults = [[self objectAtIndex: loop] rangeOfString: matchSought options:NSCaseInsensitiveSearch];
        if (searchResults.length > 0) {
            stringHolder = [self objectAtIndex: loop];
            [resultCollectorArray addObject: stringHolder];
        }
        loop++;
    }

    return [resultCollectorArray autorelease];

}

Once we get back to the main portion of the program, I get an unrecognized selector sent to the mutable array that was supposed to receive the result of the method. Here’s the main section:

#import <Foundation/Foundation.h>
#import "LookupInArray.h"

int main (int argc, const char * argv[])
{

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    NSString *testString = [[NSString alloc] initWithString: @"ab"];
    NSMutableString * resultString = [[NSString alloc] init];
    NSArray * theArray = [[NSArray alloc] initWithObjects: ..., nil];  // Actual code has the objects
    NSMutableArray *resultArray = [[NSMutableArray alloc] init];

    NSUInteger arrayCount = 0;
    unsigned long loops = 0;


    resultArray = [theArray checkForString: testString];
    arrayCount = [resultArray count];

        while (loops < arrayCount){
            resultString = [resultArray objectAtIndex: loops];  // Here's where we get the unrecognized selector.
            NSLog(@"%@", resultString);
            loops++;
    }


    [pool drain];  // Also, I'll release the objects later. I just want to get what's above working first. 
    return 0;
}

I’ve searched the other answers (for hours now), but didn’t seen anything that solved the issue.

Any and all help would be really appreciated.

And thanks beforehand.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T01:43:58+00:00Added an answer on May 23, 2026 at 1:43 am

    NSMutableArray * resultCollectorArray = [[NSMutableSet alloc] init]; is so incorrect. You are creating a mutable set and assigning it to a mutable array.

    You are getting unrecognized selector because objectAtIndex: is not a valid selector for NSMutableSet. Make that statement,

    NSMutableArray * resultCollectorArray = [[NSMutableArray alloc] init];
    

    A Better way

    NSArray * filteredArray = [array filteredArrayUsingPredicate:[NSPredicate predicateWithFormat:@"SELF contains[cd] %@", searchString]];
    

    You can directly filter the array using predicates. This way you do this in a single step. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Okay, I know I have to be doing something wrong here because the performance
Okay, I've looked all over the internet for a good solution to get PHP
Okay, here's the scenario. I have a utility that processes tons of records, and
Okay, so I'm doing my first foray into using the ADO.NET Entity Framework. My
Okay, not sure what I'm doing here, other than it's not right. Trying to
Okay. So I've got a a little jQuery gallery scroller I wrote to work
Okay. I have this code on my site: <?php session_start(); include database.php; include bruger.php;
Okay, I understand how to work delegation in a modal view to send a
Okay, so I have a snippet of code from a website containing a button:
Okay so I have two png files, a circle and a maze. Basically the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.