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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T03:06:08+00:00 2026-06-13T03:06:08+00:00

I have a singleton that I’d like to use to manage the onscreen animation

  • 0

I have a singleton that I’d like to use to manage the onscreen animation of my views. Here’s my.

#import <Foundation/Foundation.h>

@interface OAI_AnimationManager : NSObject {

    NSMutableDictionary* sectionData;
}

@property (nonatomic, retain) NSMutableDictionary* sectionData;

+(OAI_AnimationManager* )sharedAnimationManager;

- (void) checkToggleStatus : (UIView* ) thisSection;

@end

.m file

#import "OAI_AnimationManager.h"

@implementation OAI_AnimationManager

@synthesize sectionData;

+(OAI_AnimationManager *)sharedAnimationManager {

static OAI_AnimationManager* sharedAnimationManager;

@synchronized(self) {

    if (!sharedAnimationManager)

        sharedAnimationManager = [[OAI_AnimationManager alloc] init];

    return sharedAnimationManager;

}

}

- (void) checkToggleStatus : (UIView* ) thisSection {

    //get the section data dictionary
     NSLog(@"%@", sectionData);

}



@end

You’ll see in the .h file I added a NSMutableDictionary and am using @property/@synthesize for it’s getter and setter.

In my ViewController I instantiate the animation manager as well as a series of subclasses of UIView called Section. With each one I store the data (x/y w/h, title, etc.) in a dictionary and pass that to the dictionary delcared in animation manager. In the Section class I also instantiate animation manager and add a UITapGestureRecognizer which calls a method, which passes along which section was tapped to a method (checkToggleStatus) in animation manager.

As you can I see in the method I am just logging sectionData. Problem is I am getting null for the value.

Maybe my understanding of singletons is wrong. My assumption was the class would only be instantiated once, if it was already instantiated then that existing object would be returned.

I do need all the other Section classes data as if one animates others animate in response and I can get around it by passing the tapped Section to the animation manager and doing [[Section superview] subviews] and then looping and getting the data from each that way but it seems redundant since that data is available in the ViewController when they are created.

Am I doing something wrong in trying to transfer that data? Is there a better solution? I am open to suggestions and criticisms.

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-13T03:06:10+00:00Added an answer on June 13, 2026 at 3:06 am

    h file

    @interface OAI_AnimationManager : NSObject 
    
    @property (nonatomic, retain) NSMutableDictionary* sectionData;
    
    +(OAI_AnimationManager* )sharedAnimationManager;
    
    - (void) checkToggleStatus : (UIView* ) thisSection;
    
    @end
    

    m file

    static OAI_AnimationManager* _sharedAnimationManager;
    
    @implementation OAI_AnimationManager
    
    @synthesize sectionData = _sectionData;
    
    +(OAI_AnimationManager *)sharedAnimationManager {
    
    
        @synchronized(self) {
    
            if (!_sharedAnimationManager) {
    
                _sharedAnimationManager = [[OAI_AnimationManager alloc] init];
            }
        }
    
        return _sharedAnimationManager;
    
    }
    
    
    - (void) checkToggleStatus : (UIView* ) thisSection {
    
         //get the section data dictionary
    
         NSLog(@"%@", _sectionData);
    
    }
    

    @end

    Notice I moved your sectionData variable from the header and moved it to the implementation file. A while back, they changed it to where you can synthesize properties and specify their instance variable names along side it… hence:

    sectionData = _sectionData;

    I also added and underscore to the instance variable… this is a universal convention for private variables and it also will throw a compile error now if you try to type just sectionData as you did in the return statement of checkToggleStatus:. Now you either have to type self.sectionData or _sectionData.

    You didn’t include the code that creates an instance of your dictionary but I bet you didn’t set it as self.sectionData = [[NSDictionary alloc] init] which means it would not retain the value and you would get null the next time you called it. Classic memory management mistake… I know it well because I learned the hard way hehehe

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

Sidebar

Related Questions

I have a singleton here that I am trying to use the same instance
I have a singleton object that use another object (not singleton), to require some
I have a singleton that I use for creating an application wide report. As
I have a singleton class that registers a preference change listener like: PreferenceManager.getDefaultSharedPreferences(context.getApplicationContext()) .registerOnSharedPreferenceChangeListener(
I have a singleton instance that is referenced throughout the project which works like
I have a singleton class that is instantiated as follows: #import FavoritesManager.h static FavoritesManager
If you have a Java Singleton that looks like this: public class MySingleton {
I have use a singleton class that contained just one passed value. I then
I have a facade singleton that I'd like to forward some class method calls
I have a C# singleton class that multiple classes use. Is access through Instance

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.