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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T15:07:05+00:00 2026-05-26T15:07:05+00:00

First post here, so I hope it is detailed enough. While developing an Iphone

  • 0

First post here, so I hope it is detailed enough.

While developing an Iphone App I am confronted with some strange behavour. A member variable of a certain instance of my “WebserviceConnection” class seems to obtain the value I assign to another instances of the same class.

For illustration: This is en excerpt of my log. I assume the 0x000000 is an instance ID. The fourth response should be “<-: 1”.

2011-11-03 16:25:13.227 Dashboard[540:707] ->: 1, <WebserviceConnection: 0x11f950>
2011-11-03 16:25:13.256 Dashboard[540:707] ->: 0, <WebserviceConnection: 0x323db0>
2011-11-03 16:25:15.318 Dashboard[540:707] <-: 0, <WebserviceConnection: 0x323db0>
2011-11-03 16:25:15.325 Dashboard[540:707] <-: 0, <WebserviceConnection: 0x11f950>

The class is a NSUrlConnection delegate which exhibits this behavour when two connections are open at the same time.

This class: WebserviceConnection.h

(The ConnectionType is an enum)

#import "WebserviceConnection.h"
#import "WebserviceUtility.h"

@implementation WebserviceConnection

BOOL isCanceled;
NSDictionary *result;
ConnectionType connectionType;
id <WebserviceConnectionDelegate> delegate;

- (id)initWithDelegate:(id)webServiceDelegate connectionType:(ConnectionType) type {
    delegate = webServiceDelegate;
    connectionType = type;
    isCanceled = NO;
    NSLog(@"->: %i, %@", connectionType, self);
    return self;
}

- (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)data {

    switch (connectionType) {
        case GetAllAlerts:
            result = [WebserviceUtility getJsonFromData:data]; 
            break;
        case GetServerAlerts:
            result = [WebserviceUtility getJsonFromData:data]; 
            break;
        case GetServers:
            result = [WebserviceUtility getJsonFromData:data]; 
            break;
        default:
            result = nil;
            break;
    }
}

- (void)displayErrorAlert {
    UIAlertView *errorMessage = [[UIAlertView alloc] initWithTitle:@"Fout" message:@"Verbinding met webservice niet mogelijk" delegate:nil cancelButtonTitle:@"Ok" otherButtonTitles:nil];
    [errorMessage show];
}

- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error {
    if(!isCanceled) {
        @try {
            [delegate connection:connection ofType:connectionType didFinishWithError: [NSDictionary dictionaryWithObject:@"error" forKey:@"WebserverConnectionFailed"]];
        }
        @catch (NSException *e) {}
        @finally {}
        [self displayErrorAlert];
    }
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection {
    NSLog(@"<-: %i, %@", connectionType, self);
    if(!isCanceled) {
        [delegate connection:connection ofType:connectionType didFinishWithResult:result];
    }
}

- (void)connection:(NSURLConnection *)connection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
    NSURLCredential *credential = [WebserviceUtility getCredentials];
    if ([challenge previousFailureCount] == 0) {
        [[challenge sender] useCredential:credential
               forAuthenticationChallenge:challenge];
    }
    else {
        [delegate connection:connection ofType:connectionType didFinishWithError: [NSDictionary dictionaryWithObject:@"error" forKey:@"WebserverConnectionFailed"]];
        [self displayErrorAlert];

    }
}

- (void)delegateDidDealloc {
    NSLog(@"!!: %i, %@", connectionType, self);
    isCanceled = YES;
}

@end

Used like this:

- (void) getAllAlerts {
    NSURLRequest *request = [WebserviceUtility getRequestForPath:@"/dashboard/DashboardAppleConnector.asmx/GetActiveAlerts"];
    webserviceConnection = [[WebserviceConnection alloc] initWithDelegate:self connectionType:GetAllAlerts];
    connection = [[NSURLConnection alloc] initWithRequest:request delegate: webserviceConnection];
}

When another ViewController with its own webserviceConnection instance uses its instance (similar to getAllAlerts) all goed pearshaped!

Any thoughts anyone?

Regards,
Bert

  • 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-26T15:07:05+00:00Added an answer on May 26, 2026 at 3:07 pm

    It looks like the problem is happening because of the way you are declaring your variables like connectionType. If you want them to be declared as instance variables, you should be putting them in the interface declaration:

    @interface WebServiceConnection {
        BOOL isCanceled;
        NSDictionary *result;
        ConnectionType connectionType;
        id <WebserviceConnectionDelegate> delegate;
    }
    @end
    

    By declaring them in the @implementation block you are actually creating global variables, not instance variables.

    See this SO post for more information

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

Sidebar

Related Questions

My first post here, so i hope this is the right area. I am
This is my first time here so I hope I post this question at
This is my first post here and I wanted to get some input from
Hi this is my first post here hope you all are well. So Im
This is my first post here so I hope you could help me with
first post here on stack overflow, hoping to get some advice on how to
this is my first post here so I hope I provide all the right
First post here... I normally develop using PHP and Symfony with Propel and ActionScript
first post here, and probably an easy one. I've got the code from Processing's
first post here, I come in peace :) I've searched but can't quite find

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.