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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:35:18+00:00 2026-05-25T03:35:18+00:00

// Question was answered, basicly I should sleep more / code less :) When

  • 0

// Question was answered, basicly I should sleep more / code less 🙂

When my app starts i first load a splash screen, this splashscreen will start a dataDownload when the screen itself is done loading:

Splash.m

@implementation Splash


- (id) init
{
    self = [super init];

    _lblFunds = [[UILabel alloc] initWithFrame:CGRectMake(350, 330, 324,28)];
    _lblFunds.numberOfLines = 1;
    [_lblFunds setFont:[UIFont systemFontOfSize:24.0]];
    [_lblFunds setTextAlignment: UITextAlignmentCenter];
    [_lblFunds setText:@".. Fondsen .."];
    [self.view addSubview:_lblFunds];


    _lblObjects = [[UILabel alloc] initWithFrame:CGRectMake(350, 360, 324,28)];
    _lblObjects.numberOfLines = 1;
    [_lblObjects setFont:[UIFont systemFontOfSize:24.0]];
    [_lblObjects setTextAlignment: UITextAlignmentCenter];
    [_lblObjects setText:@".. Vastgoed Objecten .."];
    [self.view addSubview:_lblObjects];


    _lblCustomers = [[UILabel alloc] initWithFrame:CGRectMake(350, 390, 324,28)];
    _lblCustomers.numberOfLines = 1;
    [_lblCustomers setFont:[UIFont systemFontOfSize:24.0]];
    [_lblCustomers setTextAlignment: UITextAlignmentCenter];
    [_lblCustomers setText:@".. Clienten .."];
    [self.view addSubview:_lblCustomers];
    return self;

    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(fundsLoaded) name:@"FundsDone" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(customersLoaded) name:@"CustomersDone" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(objectsLoaded) name:@"ObjectsDone" object:nil];
}


- (void) fundsLoaded
{
    [_lblFunds setText:[NSString stringWithFormat:@"Fondsen geladen: %d",[[DataManager sharedInstance] fundsCount]]];
}

- (void) objectsLoaded
{
    [_lblObjects setText:[NSString stringWithFormat:@"Vastgoed Objecten geladen: %d",[[DataManager sharedInstance] objectsCount]]];
}

- (void) customersLoaded
{
    [_lblCustomers setText:[NSString stringWithFormat:@"Clienten geladen: %d",[[DataManager sharedInstance] customersCount]]];
}

- (void) viewDidLoad
{
    [super viewDidLoad];
    [[DataManager sharedInstance] getData];
}

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

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

@end

The DataManager will then proceed to use its instance of DataLoader to load and parse the data in a seperate thread, whenever data is parsed and stored away a Notification is sent from the DataLoader. If worked with the Notifications a lot before but this time it just will not work and I cannot seem to figure out why not. There is no error or anything, but the functions as set in the observers are never called. Any ideas on what is wrong are very much welcome, I have read quite a few threads on here, and other sites but haven’t found my answer yet.

DataManager.m

@implementation DataManager

static DataManager* _dataManager = nil;
static DataLoader *_dataLoader = nil;
static bool _dataLoaded = FALSE;

- (int) fundsCount
{
    return _dataLoader.funds_count;
}

- (int) objectsCount
{
    return _dataLoader.objects_count;
}

- (int) customersCount
{
    return _dataLoader.customers_count;
}

+ (DataManager *) sharedInstance{
    @synchronized([DataManager class])
    {
        if(!_dataManager)
        {
            _dataManager = [[super alloc] init];

            _dataLoader = [[DataLoader alloc] init];
        }
        return _dataManager;

    }
    return nil;
}

- (void) loadDataSucces
{
    _dataLoaded = TRUE;
}


- (void) _getData
{
    NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
    if(_dataLoader)
    {

        [_dataLoader loadData];

    } else
    {
        NSLog(@"DataLoader not initialized");
    }
    [pool drain];
}

- (void) getData
{
    [NSThread detachNewThreadSelector:@selector(_getData) toTarget:self withObject:nil];
}

@end

DataLoader.m

- (void) parseData: (NSString *) jsonString
{

    NSError *err;
    SBJsonParser *parser = [[SBJsonParser alloc] init];
    id object = [parser objectWithString:jsonString error:&err];
    [jsonString release];


    if (!object) {

    } else {

        //funds
        id funds = [object objectForKey:@"fondsen"];


        [self deleteAllEntitiesOfType:@"Fund"];

        int nr = 0;

        for (NSDictionary *i in funds)
        {
            NSString  *naam = [i objectForKey:@"naam"];

            if([naam length] > 2)
            {
                NSManagedObjectContext *context = [(CatalogusAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];


                Fund *f = [NSEntityDescription insertNewObjectForEntityForName:@"Fund" inManagedObjectContext: context];
                NSString *integertje = [i objectForKey:@"oid"];
                int  in = [integertje integerValue];
                [f setOid: [NSNumber numberWithInt: in    ]];
                [f setNaam: naam];
                NSError *error = nil;
                if( ![context save: &error ])
                {
                    NSLog(@"Error: %@", [[error userInfo] valueForKey:@"ErrorString"]);
                } else 
                {
                    nr++;
                }

            }

        }
        funds_count = nr;
        [[NSNotificationCenter defaultCenter] postNotificationName:@"FundsDone" object:nil];
        //objects



        if( true )
        {
            id objects = [object objectForKey:@"vastgoedobjecten"];


            [self deleteAllEntitiesOfType:@"Object"];

            nr = 0;
            NSManagedObjectContext *context = [(CatalogusAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];

            for (NSDictionary *i in objects)
            {



                Object *o = [NSEntityDescription insertNewObjectForEntityForName:@"Object" inManagedObjectContext: context];

                [o setFondsOid:[NSNumber numberWithInt: [ [i objectForKey:@"fondsOid"] integerValue]  ]];
                [o setOid: [NSNumber numberWithInt: [ [i objectForKey:@"oid"] integerValue]  ]];
                [o setAdres:[i objectForKey:@"adres"]];
                [o setPostcode:[i objectForKey:@"postcode"]];
                [o setPlaats: [ i objectForKey:@"plaats"]];
                [o setProvincie:[i objectForKey:@"provincie"]];
                [o setStatus:[i objectForKey:@"status"]];
                [o setSegment:[i objectForKey:@"segment"]];
                [o setOppervlakte:[NSNumber numberWithInt: [ [i objectForKey:@"oppervlakte"] integerValue]  ]];
                [o setBelangrijksteHuurder:[i objectForKey:@"belangrijksteHuurder"]];
                [o setWeging:[i objectForKey:@"weging"]];
                [o setLongitude:[NSNumber numberWithDouble: [ [i objectForKey:@"longitude"] doubleValue]  ]];
                [o setLatitude:[NSNumber numberWithDouble: [ [i objectForKey:@"latitude"] doubleValue]  ]];
                NSError *error = nil;
                if( ![context save: &error ])
                {
                    NSLog(@"Error: %@", [[error userInfo] valueForKey:@"ErrorString"]);
                } else 
                {
                    nr++;
                }
            }

            objects_count = nr;
            NSLog(@"ObjectsLoaded");
            [[NSNotificationCenter defaultCenter] postNotificationName:@"ObjectsDone" object:nil];

        }

        //customers
        if( true )
        {
            id custs = [object objectForKey:@"klanten"];


            [self deleteAllEntitiesOfType:@"Customer"];

            nr = 0;
            NSManagedObjectContext *context = [(CatalogusAppDelegate *)[[UIApplication sharedApplication] delegate] managedObjectContext];

            for (NSDictionary *i in custs)
            {



                Customer *c = [NSEntityDescription insertNewObjectForEntityForName:@"Customer" inManagedObjectContext: context];


                [c setOid: [NSNumber numberWithInt: [ [i objectForKey:@"oid"] integerValue]  ]];
                [c setFondsOid:[NSNumber numberWithInt: [ [i objectForKey:@"fondsOid"] integerValue]  ]];
                [c setNaam: [i objectForKey:@"naam"]];


                NSError *error = nil;
                if( ![context save: &error ])
                {
                    NSLog(@"Error: %@", [[error userInfo] valueForKey:@"ErrorString"]);
                } else 
                {
                    nr++;
                }
            }

            customers_count = nr;
            [[NSNotificationCenter defaultCenter] postNotificationName:@"CustomersDone" object:nil];

        }

    }

    [[NSNotificationCenter defaultCenter] postNotificationName:@"DataReady" object:nil];

}

- (void) loadData{

    NSString *urlString = @"URL";

    NSDate *startDownload = [NSDate date];

    NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:urlString]
                                              cachePolicy:NSURLRequestUseProtocolCachePolicy
                                          timeoutInterval:60.0];

    NSURLResponse *response = nil;
    NSError *error = nil;



    NSData *dataFeed = [NSURLConnection sendSynchronousRequest:theRequest returningResponse:&response error:&error]; 
    if(error){

        NSString *d = [ error description ];
        NSLog(@"error: %@",d);
    }    int bytes = [dataFeed length];

    NSDate *endDownload = [NSDate date];



    NSString *data = [[NSString alloc] initWithData:[NSData decompress:dataFeed] encoding:NSStringEncodingConversionExternalRepresentation];

    int string = [data length];

    NSDate *endDecompress = [NSDate date];

    NSLog(@"Download data: %f  - Decompress: %f  - BytesDownloaded: %d", [endDownload timeIntervalSinceDate:startDownload], [endDecompress timeIntervalSinceDate:endDownload], bytes);

    [[NSNotificationCenter defaultCenter] postNotificationName:@"DownloadDone" object:nil];

    [self parseData:data];

}
  • 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-25T03:35:19+00:00Added an answer on May 25, 2026 at 3:35 am

    In init, you should put your registration code BEFORE the return statement. Otherwise it will never run.

    Cheers!

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

Sidebar

Related Questions

This question is more or less the same as Restrict Certain Java Code in
This is my first question here but I'm sure there are many more to
I don't see this question answered anywhere else here. Here's the code: <div class=copyright>
After having this question answered through a link to an external site , I
Sorry if this question is answered already, but I didn't find a suitable answer.
I came across this answered question , but I can't seem to compile the
I understand that this question could be answered with a simple sentence and that
Question Answered Thank you Dan! Your code worked perfectly and you saved my life
Yesterday I had question (answered), which I have to expand a bit more today.
I know this question was answered before, but I cant still handle it with

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.