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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T13:54:09+00:00 2026-06-02T13:54:09+00:00

We must support some old code that runs using ASIHTTPRequest, but we want the

  • 0

We must support some old code that runs using ASIHTTPRequest, but we want the object mapping and core data support provided by RestKit. Does anyone know of any way of “gluing” these two together?

I picture using ASIHTTPRequest for the requests and someone manually forwarding the payload over to RestKit.

  • 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-02T13:54:11+00:00Added an answer on June 2, 2026 at 1:54 pm

    Ok, so this wasn’t too hard after all. Here is a class I wrote just for this (no disclaimers, it works for us and may be useful for someone else). You can use this as a direct replacement to the standard RKObjectLoader class.

    .h file

    #import <RestKit/RestKit.h>
    #import "ASIFormDataRequest.h"
    
    @interface ASIHTTPObjectLoader : ASIFormDataRequest <RKObjectMapperDelegate> {
        RKObjectManager* _objectManager;
        RKObjectMapping* _objectMapping;
        RKObjectMappingResult* _result;
        RKObjectMapping* _serializationMapping;
        NSString* _serializationMIMEType;
        NSObject* _sourceObject;
    NSObject* _targetObject;
    }
    
    @property (nonatomic, retain) RKObjectMapping* objectMapping;
    @property (nonatomic, readonly) RKObjectManager* objectManager;
    @property (nonatomic, readonly) RKObjectMappingResult* result;
    @property (nonatomic, retain) RKObjectMapping* serializationMapping;
    @property (nonatomic, retain) NSString* serializationMIMEType;
    @property (nonatomic, retain) NSObject* sourceObject;
    @property (nonatomic, retain) NSObject* targetObject;
    
    - (void) setDelegate:(id<RKObjectLoaderDelegate>)delegate;
    + (id)loaderWithResourcePath:(NSString*)resourcePath objectManager:   (RKObjectManager*)objectManager delegate:(id<RKObjectLoaderDelegate>)delegate;
    - (id)initWithResourcePath:(NSString*)resourcePath objectManager:(RKObjectManager*)objectManager delegate:(id<RKObjectLoaderDelegate>)delegate;             
    - (void)handleResponseError;
    
    @end
    

    .m file

    #import "ASIHTTPObjectLoader.h"
    
    @interface ASIFormDataRequest (here)
    
    - (void) reportFailure;
    - (void) reportFinished;
    
    @end
    
    @implementation ASIHTTPObjectLoader
    @synthesize objectManager = _objectManager;
    @synthesize targetObject = _targetObject, objectMapping = _objectMapping;
    @synthesize result = _result;
    @synthesize serializationMapping = _serializationMapping;
    @synthesize serializationMIMEType = _serializationMIMEType;
    @synthesize sourceObject = _sourceObject;
    
    - (void) setDelegate:(id<RKObjectLoaderDelegate>)_delegate {
        [super setDelegate: _delegate];
    }
    
    + (id)loaderWithResourcePath:(NSString*)resourcePath objectManager:(RKObjectManager*)objectManager delegate:(id<RKObjectLoaderDelegate>)_delegate {
        return [[[self alloc] initWithResourcePath:resourcePath objectManager:objectManager delegate:_delegate] autorelease];
    }
    
    - (id)initWithResourcePath:(NSString*)resourcePath objectManager:(RKObjectManager*)objectManager delegate:(id<RKObjectLoaderDelegate>)_delegate {
    
        self = [super initWithURL: [objectManager.client URLForResourcePath: resourcePath]];
    
        if ( self ) {
            self.delegate = _delegate;
            _objectManager = objectManager;
        }
    
        return self;
    }
    
    - (void)dealloc {
        // Weak reference
        _objectManager = nil;
    
        [_sourceObject release];
        _sourceObject = nil;
        [_targetObject release];
        _targetObject = nil;
        [_objectMapping release];
        _objectMapping = nil;
        [_result release];
        _result = nil;
        [_serializationMIMEType release];
        [_serializationMapping release];
    
        [super dealloc];
    }
    
    - (void) reset {
        [_result release];
        _result = nil;
    }
    
    - (void)finalizeLoad:(BOOL)successful error:(NSError*)_error {
        //_isLoading = NO;
    
        if (successful) {
            //_isLoaded = YES;
            if ([self.delegate respondsToSelector:@selector(objectLoaderDidFinishLoading:)]) {
                [self.delegate performSelectorOnMainThread:@selector(objectLoaderDidFinishLoading:)
                                                                                   withObject:self waitUntilDone:YES];            
            }
    
            [super reportFinished];
    
            /*
            NSDictionary* userInfo = [NSDictionary dictionaryWithObject:_response 
                                                                 forKey:RKRequestDidLoadResponseNotificationUserInfoResponseKey];
            [[NSNotificationCenter defaultCenter] postNotificationName:RKRequestDidLoadResponseNotification 
                                                                object:self 
                                                              userInfo:userInfo];
             */
        } else {
            NSDictionary* _userInfo = [NSDictionary dictionaryWithObject:(_error ? _error : (NSError*)[NSNull null])
                                                                 forKey:RKRequestDidFailWithErrorNotificationUserInfoErrorKey];
            [[NSNotificationCenter defaultCenter] postNotificationName:RKRequestDidFailWithErrorNotification
                                                                object:self
                                                              userInfo:_userInfo];
        }
    }
    
    // Invoked on the main thread. Inform the delegate.
    - (void)informDelegateOfObjectLoadWithResultDictionary:(NSDictionary*)resultDictionary {
        NSAssert([NSThread isMainThread], @"RKObjectLoaderDelegate callbacks must occur on the main thread");
    
        RKObjectMappingResult* result = [RKObjectMappingResult mappingResultWithDictionary:resultDictionary];
    
        if ([self.delegate respondsToSelector:@selector(objectLoader:didLoadObjectDictionary:)]) {
            [self.delegate objectLoader: (RKObjectLoader*)self didLoadObjectDictionary:[result asDictionary]];
        }
    
        if ([self.delegate respondsToSelector:@selector(objectLoader:didLoadObjects:)]) {
            [self.delegate objectLoader: (RKObjectLoader*)self didLoadObjects:[result asCollection]];
        }
    
        if ([self.delegate respondsToSelector:@selector(objectLoader:didLoadObject:)]) {
            [self.delegate objectLoader: (RKObjectLoader*)self didLoadObject:[result asObject]];
        }
    
        [self finalizeLoad:YES error:nil];
    }
    
    #pragma mark - Subclass Hooks
    
    /**
     Overloaded by ASIHTTPManagedObjectLoader to serialize/deserialize managed objects
     at thread boundaries. 
    
     @protected
     */
    - (void)processMappingResult:(RKObjectMappingResult*)result {
        NSAssert(isSynchronous || ![NSThread isMainThread], @"Mapping result processing should occur on a background thread");
        [self performSelectorOnMainThread:@selector(informDelegateOfObjectLoadWithResultDictionary:) withObject:[result asDictionary] waitUntilDone:YES];
    }
    
    #pragma mark - Response Object Mapping
    
    - (RKObjectMappingResult*)mapResponseWithMappingProvider:(RKObjectMappingProvider*)mappingProvider toObject:(id)targetObject error:(NSError**)_error {
        NSString* MIMEType = [[self responseHeaders] objectForKey: @"Content-Type"];
        id<RKParser> parser = [[RKParserRegistry sharedRegistry] parserForMIMEType: MIMEType];
        NSAssert1(parser, @"Cannot perform object load without a parser for MIME Type '%@'", MIMEType);
    
        // Check that there is actually content in the response body for mapping. It is possible to get back a 200 response
        // with the appropriate MIME Type with no content (such as for a successful PUT or DELETE). Make sure we don't generate an error
        // in these cases
        id bodyAsString = [self responseString];
        if (bodyAsString == nil || [[bodyAsString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] length] == 0) {
            RKLogDebug(@"Mapping attempted on empty response body...");
            if (self.targetObject) {
                return [RKObjectMappingResult mappingResultWithDictionary:[NSDictionary dictionaryWithObject:self.targetObject forKey:@""]];
            }
    
            return [RKObjectMappingResult mappingResultWithDictionary:[NSDictionary dictionary]];
        }
    
        id parsedData = [parser objectFromString:bodyAsString error:_error];
        if (parsedData == nil && _error) {
            return nil;
        }
    
        // Allow the delegate to manipulate the data
        if ([self.delegate respondsToSelector:@selector(objectLoader:willMapData:)]) {
            parsedData = [[parsedData mutableCopy] autorelease];
            [self.delegate objectLoader: (RKObjectLoader*)self willMapData:&parsedData];
        }
    
        RKObjectMapper* mapper = [RKObjectMapper mapperWithObject:parsedData mappingProvider:mappingProvider];
        mapper.targetObject = targetObject;
        mapper.delegate = self;
        RKObjectMappingResult* result = [mapper performMapping];
    
        // Log any mapping errors
        if (mapper.errorCount > 0) {
            RKLogError(@"Encountered errors during mapping: %@", [[mapper.errors valueForKey:@"localizedDescription"] componentsJoinedByString:@", "]);
        }
    
        // The object mapper will return a nil result if mapping failed
        if (nil == result) {
            // TODO: Construct a composite error that wraps up all the other errors. Should probably make it performMapping:&error when we have this?
            if (_error) *_error = [mapper.errors lastObject];
            return nil;
        }
    
        return result;
    }
    
    - (RKObjectMappingResult*)performMapping:(NSError**)_error {
        NSAssert( isSynchronous || ![NSThread isMainThread], @"Mapping should occur on a background thread");
    
        RKObjectMappingProvider* mappingProvider;
        if (self.objectMapping) {
            NSString* rootKeyPath = self.objectMapping.rootKeyPath ? self.objectMapping.rootKeyPath : @"";
            RKLogDebug(@"Found directly configured object mapping, creating temporary mapping provider for keyPath %@", rootKeyPath);
            mappingProvider = [[RKObjectMappingProvider new] autorelease];        
            [mappingProvider setMapping:self.objectMapping forKeyPath:rootKeyPath];
        } else {
            RKLogDebug(@"No object mapping provider, using mapping provider from parent object manager to perform KVC mapping");
            mappingProvider = self.objectManager.mappingProvider;
        }
    
        return [self mapResponseWithMappingProvider:mappingProvider toObject:self.targetObject error:_error];
    }
    
    
    - (void)performMappingOnBackgroundThread {
        NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
    
        NSError* _error = nil;
        _result = [[self performMapping:&_error] retain];
        NSAssert(_result || _error, @"Expected performMapping to return a mapping result or an error.");
        if (self.result) {
            [self processMappingResult:self.result];
        } else if (_error) {
            [self failWithError: _error];
        }
    
        [pool drain];
    }
    
    - (BOOL)canParseMIMEType:(NSString*)MIMEType {
        if ([[RKParserRegistry sharedRegistry] parserForMIMEType: MIMEType]) {
            return YES;
        }
    
        RKLogWarning(@"Unable to find parser for MIME Type '%@'", MIMEType);
        return NO;
    }
    
    - (BOOL)isResponseMappable {
        if ([self responseStatusCode] == 503) {
            [[NSNotificationCenter defaultCenter] postNotificationName:RKServiceDidBecomeUnavailableNotification object:self];
        }
    
        NSString* MIMEType = [[self responseHeaders] objectForKey: @"Content-Type"];
    
        if ( error ) {
            [self.delegate objectLoader: (RKObjectLoader*)self didFailWithError: error];
    
            [self finalizeLoad:NO error: error];
    
            return NO;
        } else if ([self responseStatusCode] == 204) {
            // The No Content (204) response will never have a message body or a MIME Type. Invoke the delegate with self
            [self informDelegateOfObjectLoadWithResultDictionary:[NSDictionary dictionaryWithObject:self forKey:@""]];
            return NO;
        } else if (NO == [self canParseMIMEType: MIMEType]) {
            // We can't parse the response, it's unmappable regardless of the status code
            RKLogWarning(@"Encountered unexpected response with status code: %ld (MIME Type: %@)", (long) [self responseStatusCode], MIMEType);
            NSError* _error = [NSError errorWithDomain:RKRestKitErrorDomain code:RKObjectLoaderUnexpectedResponseError userInfo:nil];
            if ([self.delegate respondsToSelector:@selector(objectLoaderDidLoadUnexpectedResponse:)]) {
                [self.delegate objectLoaderDidLoadUnexpectedResponse: (RKObjectLoader*)self];
            } else {            
                [self.delegate objectLoader: (RKObjectLoader*)self didFailWithError: _error];
            }
    
            // NOTE: We skip didFailLoadWithError: here so that we don't send the delegate
            // conflicting messages around unexpected response and failure with error
            [self finalizeLoad:NO error:_error];
    
            return NO;
        } else if (([self responseStatusCode] >= 400 && [self responseStatusCode] < 500) ||
                   ([self responseStatusCode] >= 500 && [self responseStatusCode] < 600) ) {
            // This is an error and we can map the MIME Type of the response
            [self handleResponseError];
            return NO;
        }
    
        return YES;
    }
    
    - (void)handleResponseError {
        // Since we are mapping what we know to be an error response, we don't want to map the result back onto our
        // target object
        NSError* _error = nil;
        RKObjectMappingResult* result = [self mapResponseWithMappingProvider:self.objectManager.mappingProvider toObject:nil error:&_error];
        if (result) {
            _error = [result asError];
        } else {
            RKLogError(@"Encountered an error while attempting to map server side errors from payload: %@", [_error localizedDescription]);
        }
    
        [self.delegate objectLoader: (RKObjectLoader*)self didFailWithError:_error];
        [self finalizeLoad:NO error:_error];    
    }
    
    #pragma mark - RKRequest & RKRequestDelegate methods
    - (void) reportFailure {
        [self.delegate objectLoader: (RKObjectLoader*)self didFailWithError:error];
    
        [super reportFailure];
    }
    
    - (void)reportFinished {
        NSAssert([NSThread isMainThread], @"RKObjectLoaderDelegate callbacks must occur on the main thread");
    
        if ([self isResponseMappable]) {
            // Determine if we are synchronous here or not.
            if (isSynchronous) {
                NSError* _error = nil;
                _result = [[self performMapping:&_error] retain];
                if (self.result) {
                    [self processMappingResult:self.result];
                } else {
                    [self performSelectorInBackground:@selector(failWithError:) withObject:_error];
                }
    
                [super reportFinished];
            } else {
                [self performSelectorInBackground:@selector(performMappingOnBackgroundThread) withObject:nil];
            }
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a program that must support both Oracle and SQL Server for it's
I'm working on a client-server application (.NET 4, WCF) that must support backwards compatibility.
I'm building an application that must support MSSQL and MySQL databases. To avoid duplication
We have a data model that has some requirements. I would like to find
In our project now we using log4cxx, but those library don't develope some years,
I´m really glad that I must no more use IETester since IE6 support was
I'm building a project along with a Dll. The Dll must support native code
I'm implementing mixins using C++ templates to support some extended behaviors for a base
We've got some old serial code which checks whether a serial port is available
I'm working on some old AJAX code, written in the dark dark days before

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.