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 8252127
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T00:28:02+00:00 2026-06-08T00:28:02+00:00

When you retrieve the ID of a selector with @selector() , is the selector

  • 0

When you retrieve the ID of a selector with @selector(), is the selector value different depending on the types of the arguments?

Here’s what I mean. I have a method that takes an object reference and a selector, then calls it with a parameter:

-(void)CallLater:(NSObject*) Obj Sel: (SEL)Sel
{
    //Some stuff, then:
    [Obj performSelector: Sel withObject: SomeOtherObject];
}

I’m using this method with a selector to a function that takes a typed object reference, not an id:

-(void)MyMethod: (MyObject*) a
{
}

[self CallLater: self Sel:@selector(MyMethod:)];

It seems to work, but my senses are tingling. In a statically typed language like C# this would be a foul, an upcast – CallLater is expecting a selector for a function that takes an id and I’m giving it a function that takes a MyObject.

On the other hand, the compiler does not complain, and both id and concrete object references seems to be mere pointers deep down, trivially castable to one another. Then again, there are many fouls that Objective C compiler does not complain about.

So the real question is – is it safe? Language lawyers welcome.

  • 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-08T00:28:03+00:00Added an answer on June 8, 2026 at 12:28 am

    It’s safe; objects are objects. A selector parameter for an NSObject * is exactly the same as a selector parameter for a MyObject *.

    If you want MyMethod to verify that it’s being called with an object of a particular type, it should do a NSParameterAssert on it:

    NSParameterAssert([obj isKindOfClass: [MyObject class]]);
    

    Personally, I rarely do this check. It’s enough that the actual object acts like the type I want it to be, and if it doesn’t I’ll get a runtime error (usually unrecognized selector). You’ll get a compiler warning in the simple cases, and it’s worth paying attention to this warning (and silencing it with an id cast when necessary).

    I’m a bit confused here about your use of id in your question, so I want to make sure you understand this: An NSObject * is exactly as much an id as a MyObject * is. id is a generic instance pointer class, whereas NSObject * is a NSObject instance (or a subclass of NSObject). You can have objects that don’t descend from NSObject. But you’re unlikely to ever have to know this.

    Other notes, re: convention:

    • Selectors (both the name and parameters) start with lowercase letters, so CallLater:Sel: should be callLater:sel:.
    • Variable and parameter names start with lowercase letters; Obj above should be obj.
    • Class names do start with an uppercase letter. 🙂
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a method (getAllTeams:) that initiates an HTTP request using the ASIHTTPRequest library.
I am communicating with a webservice to retrieve a numerical value that comes into
I am trying to retrieve an array of jquery object from selector, so I
I retrieve XML data in Flex via HttpService. I have the resultFormat property on
I retrieve data from db like that: select * from MOVIE_COMMENT where USER_ID =
I retrieve a list of ObjectId and I want to retrieve all object in
I have to hidden input fields such as: <input name=foo value=bar> <input name=foo1 value=bar1>
I am trying to retrieve value for id : {id:1,name:XYZ} When I use: NSString
I have a NSArray that contain three keys with their corresponding values… When I
i'm searching implementing a UISearchbar that retrieve information from a url, and with 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.