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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 19, 20262026-06-19T04:43:59+00:00 2026-06-19T04:43:59+00:00

I am facing an issue while using NSInvocation with arguments which are not objects.

  • 0

I am facing an issue while using NSInvocation with arguments which are not objects.
The simple integer value that I pass gets changed to something different.

Here is the method I am invoking:

+(NSString*) TestMethod2 :(int32_t) number
{
    NSLog(@"*************** %d ******************", number);
    return @"success";
}

And This is how I am calling it :

-(void) TestInvocationUsingReflection
{
    id testClass = NSClassFromString(@"TestClass");
    NSMethodSignature * methodSignature = [testClass methodSignatureForSelector:@selector(TestMethod2:)];

    NSInvocation *inv = [NSInvocation invocationWithMethodSignature:methodSignature];
    [inv setSelector:@selector(TestMethod2:)];
    [inv setTarget:testClass];
    NSNumber * arg = [NSNumber numberWithInt:123456];

    [inv setArgument:&arg atIndex:2]; //arguments 0 and 1 are self and _cmd respectively, automatically set by NSInvocation
    [inv retainArguments];
    NSUInteger length = [[inv methodSignature] methodReturnLength];
    id result = (void *)malloc(length);

    [inv invoke];
    [inv getReturnValue:&result];

}

The result is what gets logged is not the simple 123456 value I pass but something like this:

****** 180774176 *********

What is it that I am doing wrong?

I am pretty new to Objective C but, I need to invoke a method at runtime over which I have no control. And it takes int64_t as the argument type.

Please can anyone help?
Thanks….

  • 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-19T04:44:00+00:00Added an answer on June 19, 2026 at 4:44 am

    You’re passing an NSNumber* as the argument, not an int_32t. The NSNumber happens to wrap the integer, but it’s not an integer.

    Note that retainArguments may expect that the arguments are objects that can be retained. Its documentation does mention that C strings are copied, but it’s not immediately obvious what happens to scalars like an int. You probably should avoid retainArguments and manage retaining and releasing yourself.

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

Sidebar

Related Questions

i am using Codeigniter i am facing an issue while setting the values of
I am facing some issues while serializing objects (I am using JBoss Drools, and
We have implemented webservice which generates xml response. I am facing issue while invoking
I am learning sencha touch. I am facing an issue while using xtype:'list', in
i am facing an issue while using sikuli through java, if there are 2
I am facing an issue Empty id attribute is not allowed in JSF while
I am facing an error while minification of scripts using ajaxmin which contains 'eval'.
I am a developer and I am facing an issue while managing table which
This is a weird issue that I am facing while forms authentication. I am
I am facing a strange issue while using javascript setTimeout function in IE8. I

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.