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

  • Home
  • SEARCH
  • 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 8225045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:16:55+00:00 2026-06-07T15:16:55+00:00

I am doing an exercise to learn how to use selectors in Objective-C. In

  • 0

I am doing an exercise to learn how to use selectors in Objective-C.
In this code I am trying to compare two strings:

int main (int argc, const char * argv[])
{
    @autoreleasepool
    {
        SEL selector= @selector(caseInsensitiveCompare:);
        NSString* str1=@"hello";
        NSString* str2=@"hello";
        id result=[str1 performSelector: selector withObject: str2];
        NSLog(@"%d",[result boolValue]);
    }
    return 0;
}

But it prints zero.Why?

Edit:
And if I change str2 to @”hell” I get an EXC_BAD_ACCESS.

  • 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-06-07T15:16:56+00:00Added an answer on June 7, 2026 at 3:16 pm

    The documentation for performSelector: states “For methods that return anything other than an object, use NSInvocation”. Since caseInsensitiveCompare: returns an NSInteger instead of an object you will need to create an NSInvocation, which is more involved.

    NSInteger returnVal;
    SEL selector= @selector(caseInsensitiveCompare:);
    NSString* str1=@"hello";
    NSString* str2=@"hello";
    
    NSMethodSignature *sig = [NSString instanceMethodSignatureForSelector:selector];
    NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:sig];
    [invocation setTarget:str1];
    [invocation setSelector:selector];
    [invocation setArgument:&str2 atIndex:2]; //Index 0 and 1 are for self and _cmd
    [invocation invoke];//Call the selector
    [invocation getReturnValue:&returnVal];
    
    NSLog(@"%ld", returnVal);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am doing this small exercise. declare @No decimal(38,5); set @No=12345678910111213.14151; select @No*1000/1000,@No/1000*1000,@No; Results
Preface: I'm very new to objective-c and I am doing simple exercises to learn
After doing my exercise in school, I use Sqlite to store my data. But
I am on exercise 43 doing some self-directed work in Learn Python The Hard
I am doing exercise on Singpath and I am stuck at this question. This
I am learning python atm, and was doing an exercise from this site --
I am doing exercise 26 in learn python the hard way and have been
I am trying to complete Exercise 47 of Learn Python The Hard Way, 2nd
I am doing a training exercise in Scala and getting this val reassignment error.
I must have missed something. I'm doing an exercise to learn c++ and it

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.