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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T15:10:22+00:00 2026-06-09T15:10:22+00:00

I have tried using a singleton class in my app delegate but I haven’t

  • 0

I have tried using a singleton class in my app delegate but I haven’t been able to get that to work. I’ve also checked out the iAdSuite examples (particularly the containerBanner example because it seemed to be the most relative) but I can’t figure it out. If there’s a better way to accomplish this without using a singleton class and you can point me in the right direction I’d really appreciate it. Some of my singleton class code is below. Thank you!

@interface App Delegate

@property (assign) iAdController *iadc;
+ (AppDelegate*) sharedApplication;
- (iAdController*)sharedAd;
@end

@implementation AppDelegate

@synthesize iadc;

+ (AppDelegate*) sharedApplication
{
return [[UIApplication sharedApplication] delegate];
}

-(iAdController*)sharedAd
{
    if(iadc==nil){
        iadc=[iAdController new];
    }
    return iadc;
}


@interface ViewController

iAdController*iadc=[[AppDelegate sharedApplication] sharedAd];
//here i get an error saying, "initializer element is not a compile-time constant.

Everything is imported correctly. If there’s anything else I should post let me know.

  • 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-09T15:10:24+00:00Added an answer on June 9, 2026 at 3:10 pm

    try changing your singleton creation to this:

    + (LocationManagerSingleton*)sharedInstance {
    
        static LocationManagerSingleton *_sharedInstance;
        if(!_sharedInstance) {
            static dispatch_once_t oncePredicate;
            dispatch_once(&oncePredicate, ^{
                _sharedInstance = [[super allocWithZone:nil] init];
            });
        }
    
        return _sharedInstance;
    }
    
    
    
    + (id)allocWithZone:(NSZone *)zone {    
    
        return [self sharedInstance];
    }
    
    
    - (id)copyWithZone:(NSZone *)zone {
        return self;    
    }
    
    - (id)init
    {
        self = [super init];
        if (self != nil) 
        {
            // PERFORM any custom initialization here
        }
        return self;
    }
    

    Obviously change the name of the class.

    Whenever you want to use your singleton in any of your viewcontrollers just call it like this:

    locationManager = [LocationManagerSingleton sharedInstance];
    

    Dont forget to add

    + (LocationManagerSingleton*) sharedInstance;
    

    on the header.

    EDIT

    well it seems i misunderstood your code (forget my answer, you simply want to be able to access your iAdController from everywhere. so just place

    Add inside the .m of the ViewController

    @interface ViewController()
    {
        iAdController *iadc; 
    }
    

    And inside the

    -(void)viewDidLoad
    {
        iadc=[[AppDelegate sharedApplication] sharedAd];
    }
    

    but import the app delegate.h on whichever viewcontroller you want to use it in.

    #import "AppDelegate.h" 
    

    also there shouldnt be a space in the AppDelegate on the @interface

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

Sidebar

Related Questions

I have tried using the accordion plugin, but it does not work, and I
I have tried using date(m/d/Y, strtotime(04-05-2012)) but I will get 05/04/2012 or on some
How can I avoid NullPointerExceptions ? I have tried using try-catch blocks but that
I have used singleton calss following the example: singleton class But i get the
I have tried using the code below but it only display results in Chrome
I have tried using a stemmer but the words it produces are just not
We have tried it using an orm mapper tool, but it opens en closes
I have a static class in my ASP.NET app that I use to hold
So far I have tried using 'setParseAction' to get the location of matched tokens,
I have tried using position fixed but I just cannot seem to find out

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.