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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T00:34:59+00:00 2026-05-31T00:34:59+00:00

I’m trouble porting a static library for our cloud database service to ARC. I’ve

  • 0

I’m trouble porting a static library for our cloud database service to ARC.

I’ve got to the stage where it compiles and runs but it’s never calling back the delegate.

I have 2 classes, a proxy class and an APIOperation.

The APIOperation is a subclass of NSOperation that uses NSURLConnection to fetch data from a web API.

The proxy has an NSOperationQueue, and basically is the delegate for all the APIOperation calls.

The usage model is as follows:

  • User class creates instance of proxy object.
  • Proxy instantiates APIOperation object and adds it to NSOperationQueue
  • APIOperation creates NSURLConnection
  • On connectionDidFinishLoading
    • Response is parsed then passed back to proxy class via NSInvocation.
    • Proxy class calls delegate (the user class) and passes back the API response.

The code is as follows:

proxy class:

@implementation theProxy

@synthesize callbackSelector,delegate,opQueue;

-(theProxy*)init{
    opQueue = [[NSOperationQueue alloc]init];
    return self;
}

- (void) apiOperation:(APIOperation*)operation didCompleteWithResult:(NSArray*)theResult{
    SEL selector = [operation callbackSelector];
    if ([delegate respondsToSelector:selector]) {
    NSInvocation* inv = [NSInvocation invocationWithMethodSignature:[[delegate class] instanceMethodSignatureForSelector:selector]];
    [inv setTarget:delegate];
    [inv setSelector:selector];
    theProxy* tmp = self;
    [inv setArgument:&tmp atIndex:2];
    [inv setArgument:&operation atIndex:3];
    [inv setArgument:&theResult atIndex:4];
    [inv invoke];        
}

}

- (void) apiOperation:(APIOperation*)operation didFailWithError:(NSString*)theError{
if ([delegate respondsToSelector:@selector(API:apiOperation:didFailWithError:)]) {
    [delegate API:self apiOperation:operation didFailWithError:theError];
}
}

-(void)cancelAllOperations{
[opQueue cancelAllOperations];
}

- (void)dealloc
{
[opQueue cancelAllOperations];
[opQueue release], opQueue = nil;
delegate = nil;
//[delegate release];  delegate should not be retained.

[super dealloc];
}

APIOperation class (vastly simplified):

@implementation APIOperation
@synthesize delegate,APIKey,secretKey,debugMode,callbackSelector,successCallbackMethodSignature,errorCallbackMethodSignature,delegateCallbackMethodSignature,tag,APIServer,requestProcessingTime,requestReceivedTime,responseCode,responseMessage,timestamp,requestRoundTripTime,requestStartMicroTime,useSSL;

-(void) main{
    receivedData = [NSMutableData data];
    connFinished = NO;
    // create the connection with the request
    // and start loading the data
    theConnection=[[NSURLConnection alloc] initWithRequest:[self buildRequest] delegate:self];
    if (theConnection) {

        do {
            [[NSRunLoop currentRunLoop] runMode:NSDefaultRunLoopMode beforeDate:[NSDate distantFuture]];
            } while (!connFinished);
    }
}

- (void)connectionDidFinishLoading:(NSURLConnection *)connection{

    id pList = [NSPropertyListSerialization propertyListFromData:receivedData mutabilityOption:NSPropertyListImmutable format:&format errorDescription:&errorStr];

    theResponse = (NSDictionary*) pList;

    if ([delegate respondsToSelector:@selector(apiOperation: didCompleteWithResult:)]) {

        NSArray* theResultsArray = [theResponse objectForKey:@"payload"];

        NSInvocation *inv = [NSInvocation invocationWithMethodSignature:successCallbackMethodSignature];
        [inv setTarget:delegate];
        [inv setSelector:@selector(apiOperation: didCompleteWithResult:)];
        KSAPIOperation* tmp = self;
        [inv setArgument:&tmp atIndex:2];
        [inv setArgument:&theResultsArray atIndex:3];
        [inv performSelectorOnMainThread:@selector(invoke) withObject:nil waitUntilDone:YES];

    }       
}
@end

Now as I say this works up until the line ‘if([delegate respondsToSelector…’ in connectionDidfinishLoading. At that point it always returns false. Now assuming this is to do with ARC, I’ve checked that the delegate is not null and the value is there, also the delegate property is declared in APIOperation.h as:

@property (unsafe_unretained) id<KSAPIOperationDelegate,NSObject> delegate;

If I remove the respondsToSelector check then the app crashes in main() with the following backtrace:

#0  0x0156b09b in objc_msgSend ()
#1  0xbfffde10 in ?? ()
#2  0x0132d437 in -[NSInvocation invoke] ()
#3  0x013c8e72 in -[NSObject performSelector:withObject:] ()
#4  0x009369ef in __NSThreadPerformPerform ()
#5  0x0139b97f in __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ ()
#6  0x012feb73 in __CFRunLoopDoSources0 ()
#7  0x012fe454 in __CFRunLoopRun ()
#8  0x012fddb4 in CFRunLoopRunSpecific ()
#9  0x012fdccb in CFRunLoopRunInMode ()
#10 0x012b0879 in GSEventRunModal ()
#11 0x012b093e in GSEventRun ()
#12 0x0001ea9b in UIApplicationMain ()
#13 0x00002a58 in main (argc=1, argv=0xbfffed50) at /Users/MikeW/Desktop/ARC test proj/lib1.0Test/lib1/main.m:16
#14 0x000029b5 in start ()

Would appreciate any help you can offer.

Thanks

Mike

  • 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-31T00:35:01+00:00Added an answer on May 31, 2026 at 12:35 am

    As David suggested it was a problem of the delegate being released.

    The problem was resolved by simply making the property “(strong)” rather that unsafe_unretained or __weak.

    @property (strong) id<KSAPIOperationDelegate,NSObject> delegate;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
We're building an app, our first using Rails 3, and we're having to build
I need to clean up various Word 'smart' characters in user input, including but
We are using XSLT to translate a RIXML file to XML. Our RIXML contains
public static bool CheckLogin(string Username, string Password, bool AutoLogin) { bool LoginSuccessful; // Trim

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.