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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:36:31+00:00 2026-06-06T05:36:31+00:00

I want to pass 2 variables: UIImage * img int i into another method

  • 0

I want to pass 2 variables:

UIImage * img
int i

into another method that only takes a (void *)

I tried making a C struct containing both img and i

struct MyStruct {
    UIImage *img;
    int i;
}

but xcode gives me an error saying “ARC forbids Objective-C objects in structs or unions”

The next thing I tried is to write an objective-c class MyStruct2 containing img and i, alloc-initing an instance of it and typecasting it as (__bridge void*) before passing it to the method. Seems little involved for my use case. Seems like there should be a better way.

What’s the simplest way to achieve this?

Thank you.

Edit based on comments: I have to use void * as it is required by the UIView API. I created a selector as mentioned by UIVIew API

+ (void)setAnimationDidStopSelector:(SEL)selector

Please see documentation for setAnimationDidStopSelector at http://developer.apple.com/library/ios/#documentation/uikit/reference/UIView_Class/UIView/UIView.html . It says … The selector should be of the form:

    - (void)animationDidStop:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context 

I want to pass both img and i into the (void *)context argument.

  • 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-06T05:36:34+00:00Added an answer on June 6, 2026 at 5:36 am

    ARC cannot follow ObjC objects in plain old C structs. It tracks pointers on the stack, or in ObjC and C++ objects, which are copied using methods, explicit or implicit, but under the compiler control anyway.

    So… use a class. C++ if you like it, or :

    @interface MyNotSoPlainStruct
    
    @property ( nonatomic, strong ) UImage* image;
    @property ( nonatomic ) int i;
    
    @end
    
    @implementation MyNotSoPlainStruct
    @end
    
    MyNotSoPlainStruct* foo = [MyNotSoPlainStruct new];
    foo.image = …
    foo.i = …
    

    and there you go.

    The solution needs more lines, that’s true, but you have a much better control on how things are done, including the image life cycle. You can use a strong pointer, or a weak one if it suits your needs better.

    Of course, you can also use either a dictionary or an array. Literals make that especially easy:

    NSDictionary* arguments = @{ @"image" : <image>, @"i" : @( <int> ) };
    arguments[@"i"].intValue returns the int you need.
    

    Pretty easy.

    edit

    Forgot the transfer part, oops :). So then:

    You must use the following annotations:

    void* argumentsPointer = (__bridge_retained void*) arguments;
    

    arguments is retained, and that reference is no longer managed by ARC.

    When you receiver your pointer back, you must convert it:

    NSDictionary* arguments = (__bridge_transfer NSDictionary*) argumentsPointer;
    

    Using __bridge only may result in a dangling pointer if the last known reference disappear. If you want that void* to retain the dictionary, you must use __bridge_retained first, then __bridge_transfer.

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

Sidebar

Related Questions

I want to pass my variables into that template, let it render, and then
i want to pass large variables to a PHP script on another server with
I want to pass a few variables to another page. Currently I'm using response.redirect
I want to pass some variables from one class to another, but the code
I want to pass another value to the method LeCmb_Statut_SelectedIndexChanged, how can I proceed?
I want to pass some PHP variables using the URL. I tried the following
Heading I want to pass some variables from one page to another but I
I got Form1 with some variables and I want to pass it to another
I want to pass a variable to he buttonEvent method in the selector. [button
I want to pass first directory as a variable and subdirectory as another variable.

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.