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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:03:48+00:00 2026-06-12T16:03:48+00:00

I need to check the return type of an NSInvocation to see if it

  • 0

I need to check the return type of an NSInvocation to see if it is an object (from there I can use isKindOfClass: to check the exact kind of object). I see that NSInvocation has an NSMethodSignature, which in turn has methodReturnType. However, the documentation gives the following warning:

This encoding is implementation-specific, so applications should use it with caution.

So, how do I safely check if the return type is an object? Is there a decode variant of @encode(type-name)?

  • 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-12T16:03:49+00:00Added an answer on June 12, 2026 at 4:03 pm

    In short, you can’t. At least, not with 100% fidelity.

    For simple types like doubles, floats, ints, ids, etc… you can check the return type and then deal with it in a platform specific fashion. For more complex types — structs, C++ objects, etc… — you could go down the path of trying to figure out just how, exactly, the C ABI would have laid out the data on a per-ABI basis, but you’ll end up re-inventing the compiler in the process.

    Fortunately, there are some really comprehensive examples of how all this works. Both the PyObjC and RubyCocoa (MacRuby) projects are open source and provide relatively complete support for arbitrary return values. Relatively; you’ll still be hosed on complex types.

    All in all, Objective-C is purely dynamic at dispatch but very much a C derived static language in terms of argument passing and return values.


    Missed your final sentence. The derp is strong prior to coffee.

    This is the set of characters that might be returned by methodReturnType.

    You’ll be looking for @. Given that methodReturnType returns a const char *, you may encounter cases where an object return type returns more than just an @; there may be modifiers attached to it. You’ll have to test a boatload of method’s return types to see if that is actually the case (the generation of said metadata has changed over the years and is also influenced by the use of various keywords in method declarations).

    However, most of the time @ is good enough to conclude that it is an object return type. Most will increase in truthiness for methods of your own declaration (where you, hopefully, don’t do anything exceedingly odd, from the compiler’s perspective).

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

Sidebar

Related Questions

The one thing that can still get me is what to return from methods?
I need to check to see if a directory is empty. The problem is,
I need to check if my address has any words that matches word in
I need to check in some fast way if there is any text nodes
First the code: class myClass(object): def __cmp__(self, other): return cmp(type(self), type(other)) or cmp(self.__something, other.__something)
In C++/CLI code I need to check if the type is a specific generic
I want to check the mime-type of uploaded file in php and return true
I need to check that specific string contains in the set of others: private
As return type does not play any role in function overloading,and compiler only check
I am working with stacks and need to check to see if two are

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.