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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T11:11:55+00:00 2026-05-29T11:11:55+00:00

Class A has a UIImage. Class B has a static reference to a class

  • 0

Class A has a UIImage.

Class B has a static reference to a class of type A.

Before class B is instantiated, I want to call a static method in class B to assign an instance of class A.

+ (void)setClassAReference:(ClassA*)classA
{
    classA_ = classA;
}

Is this possible?

Before I delved into my current project, I created a sample one, and was able to set an integer value, then instantiate B with it keeping the stored value and allowing access to it.

However, in my current project, XCode refuses to allow me to pass an integer value:

Non-static method in class A:

- (UIImage*)imageWithIdentifier:(ImageIdentifier)identifier; // identifier is enum type

After class B is instantiated, I try to call a method in A:

UIImage *img = [classA_ imageWithIdentifier:ImageIdentifier_Foo];

But I get an implicit conversion warning. The auto-complete shows (id) instead of (ImageIdentifier). I’ve triple-checked all my method signatures and they all use the enum type.

Am I using static variables incorrectly or is there another problem? I realize I could use a singleton, but I’d prefer not to if possible.

I’m adding the enum declaration here:*

typedef enum
{
  ImageIdentifier_Foo = 0,
  ImageIdentifier_Bar
} ImageIdentifier;

*real names changed to protect the innocent.

  • 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-05-29T11:11:57+00:00Added an answer on May 29, 2026 at 11:11 am

    Firstly…

    If you want to initialize static variables on a class before it is instantiated you use the class method on NSObject

    + (void) initialize
    

    This is where you can assign your static ClassA variable in ClassB.

    Secondly….

    Make sure you retain that classA variable, otherwise it will be released.

    Thirdly…..

    Regarding your implicit conversion… what is variable ‘a’, above this you wrote classA_. Can you show your enum declaration. Have you imported ClassA ?

    I don’t have any compile error with this:

    ClassA.h

    typedef enum
    {
        ImageIdentifier_Foo = 0,
        ImageIdentifier_Bar
    } ImageIdentifier;
    
    @interface ClassA : NSObject
    
    - (UIImage*)imageWithIdentifier:(ImageIdentifier)identifier; // identifier is enum type
    
    @end
    

    ClassA.m

    #import "ClassA.h"
    
    @implementation ClassA
    
    - (UIImage*)imageWithIdentifier:(ImageIdentifier)identifier {
        return nil;
    }
    
    @end
    

    ClassB.h

    @interface ClassB : NSObject
    
    @end
    

    ClassB.m

    #import "ClassB.h"
    #import "ClassA.h"
    
    static ClassA *classA;
    
    @implementation ClassB
    
    + (void) initialize {
        classA = [[ClassA alloc] init];
    }
    
    - (void) doSomething {
        UIImage *image = [classA imageWithIdentifier:ImageIdentifier_Foo];
        NSLog(@"image %@", image);
    }
    
    @end
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Although a static class has only one instance and can't be instantiated, a class
A class has a property (and instance var) of type NSMutableArray with synthesized accessors
StreamReader class has both close and dispose method. I want to know which method
My project has a UIImage category function that I want to call from another
Some class has ugly field called URL, but Id rather call it file. public
A TreeNode class has Text Name Tag I need to assign more values to
If a class has a private constructor then it can't be instantiated. So, if
Thread class has run method to implement the business logic that could be executed
I have a custom class, and that class has a UIButton instance variable. I
I have a UIViewController subclass called TripViewController. This class has the following method: -

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.