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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T07:04:15+00:00 2026-05-29T07:04:15+00:00

I decided to try and make a Singleton for use with locations. I have

  • 0

I decided to try and make a Singleton for use with locations. I have got what I think to be, the singleton working correctly however I have one error that is now appearing. It tells me that my implementation is incomplete. It is the only error it is giving me and I am sure it is something wrong with either my view header or m file. I have tried a few things now and cannot get it to work. What am I missing here?

Here is my header

#import <UIKit/UIKit.h>

@interface TrackerViewController : UIViewController
-(void) locationUpdate;
end

And here is my implementation file:

#import "TrackerViewController.h"
#import "MyLocation.h"

@implementation TrackerViewController

NSString *LatCoord;
NSString *LongCoord;

- (void)didReceiveMemoryWarning
{
  [super didReceiveMemoryWarning];
  // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

- (void)viewDidLoad
{
  [super viewDidLoad];
  [LocationController sharedInstance].locDelegate = (id)self;
  // Do any additional setup after loading the view, typically from a nib.
}

- (void)viewDidUnload
{
  [super viewDidUnload];
  // Release any retained subviews of the main view.
  // e.g. self.myOutlet = nil;
}

- (void)viewWillAppear:(BOOL)animated
{
  [super viewWillAppear:animated];
}

- (void)viewDidAppear:(BOOL)animated
{
  [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
  [super viewWillDisappear:animated];
}

- (void)viewDidDisappear:(BOOL)animated
{
  [super viewDidDisappear:animated];
}

- (void)locationUpdate:(CLLocation *)location {
    [[LocationController sharedInstance] setLocation:location];
    LatCoord  = [NSString stringWithFormat:@"%lf", location.coordinate.latitude];
    LongCoord = [NSString stringWithFormat:@"%lf", location.coordinate.longitude];
}

- (BOOL)shouldAutorotateToInterfaceOrientation (UIInterfaceOrientation)interfaceOrientation
{
  // Return YES for supported orientations
  return YES;
}

-(IBAction)CheckIn:(id)sender 
{
  [self locationUpdate];
}

@end

My singleton header is as follows:

#import <Foundation/Foundation.h>
#import <CoreLocation/CoreLocation.h>

@protocol LocationControllerDelegate <NSObject>
@required
- (void)locationUpdate:(CLLocation*)location;
@end

@interface LocationController : NSObject <CLLocationManagerDelegate> {

  __unsafe_unretained id <LocationControllerDelegate> _locDelegate;

  CLLocationManager* locationManager;
  CLLocation* location;
  id locDelegate;
}

@property (nonatomic, retain) CLLocationManager* locationManager;
@property (nonatomic, retain) CLLocation* location;
@property (nonatomic, assign) id <LocationControllerDelegate> locDelegate;

+ (LocationController*)sharedInstance;

@end

My singleton implementation is as follows:

#import "MyLocation.h"

static LocationController* sharedCLDelegate = nil;

@implementation LocationController
@synthesize locationManager, location, locDelegate = _locDelegate;

- (id)init
{
 self = [super init];
 if (self != nil) {
   self.locationManager = [[CLLocationManager alloc] init];
   self.locationManager.delegate = self;
   self.locationManager.desiredAccuracy = kCLLocationAccuracyBest;
 }
 return self;
}

- (void)dealloc
{
 /* ... */
}

#pragma mark -
#pragma mark CLLocationManagerDelegate Methods
- (void)locationManager:(CLLocationManager*)manager
   didUpdateToLocation:(CLLocation*)newLocation
       fromLocation:(CLLocation*)oldLocation
{
 /* ... */
}

- (void)locationManager:(CLLocationManager*)manager
    didFailWithError:(NSError*)error
{
  /* ... */

}

#pragma mark -
#pragma mark Singleton Object Methods

+ (LocationController*)sharedInstance {
  @synchronized(self) {
    if (sharedCLDelegate == nil) {
    }
  }
  return sharedCLDelegate;
}

+ (id)allocWithZone:(NSZone *)zone {
  @synchronized(self) {
    if (sharedCLDelegate == nil) {
        sharedCLDelegate = [super allocWithZone:zone];
        return sharedCLDelegate;  
    }
  }
  return nil;
}

- (id)copyWithZone:(NSZone *)zone
{
  return self;
}


@end

What am I missing or doing wrong here?

  • 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-29T07:04:15+00:00Added an answer on May 29, 2026 at 7:04 am

    Your singleton looks wrong. Your sharedInstance method should be:

    + (LocationController*)sharedInstance {
      @synchronized(self) {
        if (sharedCLDelegate == nil) {
          sharedCLDelegate = [[self alloc] init];
        }
      }
      return sharedCLDelegate;
    }
    

    And you can get rid of the allocWithZone: and copyWithZone: methods – they don’t do anything useful.

    That’s most likely why your class isn’t working, but probably has nothing to do with the “incomplete implementation” warning. The warning will be because you’ve forgotten to implement a method that’s declared in your header or in one of your protocols, or maybe you’ve misspelled it. I couldn’t spot it on a first pass, but I’ll take another look.

    If you double-click on the yellow warning icon in the header it should tell you which method hasn’t been implemented properly.

    By the way, the line below leaks because you’re double-retaining (init sets retain count to one, and then assigning to a retained property sets it to 2). You should run the Analyze function, which will add blue warnings for leaks like this.

    self.locationManager = [[CLLocationManager alloc] init];
    

    Do one of the following instead:

    //assign directly to the ivar so the setter method isn't used
    locationManager = [[CLLocationManager alloc] init];
    

    Or

    //autorelease before assigning
    self.locationManager = [[[CLLocationManager alloc] init] autorelease];
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a working WAMP environment (Apache Friends). I decided to try Subversion and
I decided I should try to implement coroutines (I think that's how I should
I have a project I am working on. I have decided to try working
I'm coming from a TortoiseSVN background and decided to give TortoiseHg a try. One
I use PHP to generate files of some special format, and I have decided
I got sick of looking up the magic symbols in make and decided to
I'm working with an old app that had hard coded columns for different locations,
I have just decided to try out the Android SDK, so I installed it
I decided to try http://www.screwturn.eu/ wiki as a code snippet storage utility. So far
So I've decided to try to solve my physics homework by writing some python

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.