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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:41:34+00:00 2026-05-25T13:41:34+00:00

I am trying to store a REST connection model in a single object so

  • 0

I am trying to store a REST connection model in a single object so that I don’t keep having to use it over and over again. Here is the model I created:

//RestModel.h
#import "ASIHTTPRequest.h"

@interface RestModel : NSObject{
    NSString* _baseUrl;
    NSString* _modelUrl;
}

@property (nonatomic, retain) NSString* modelUrl;

- (id)initWithModel:(NSString*)model;
- (NSDictionary*)getById:(NSInteger*)ident;
- (NSDictionary*)getAll;

@end

//RestModel.m
#import "RestModel.h"

@implementation RestModel

@synthesize modelUrl = _modelUrl;

- (id)init
{
    self = [super init];
    if (self) {
        _baseUrl = @"http://myRESTurl.com";
    }

    return self;
}

- (id)initWithModel:(NSString*)model
{
    self = [super init];
    if (self) {
        _baseUrl = @"http://myRESTurl.com";
        self.modelUrl = [NSString stringWithFormat:@"%@/%@/", _baseUrl, model];
    }

    return self;
}

- (NSDictionary*)HTTPRequest:(NSURL*)url
{
    ASIHTTPRequest *request = [ASIHTTPRequest requestWithURL:url];
    [request startSynchronous];
    NSError *error = [request error];
    if(!error){
        NSData *responseData = [request responseData];
        NSString *errorDesc = nil;
        NSPropertyListFormat format;

        [error release]; 
        [request release];

        return (NSDictionary*)[NSPropertyListSerialization propertyListFromData:responseData mutabilityOption:NSPropertyListMutableContainersAndLeaves format:&format errorDescription:&errorDesc];
    }else{
        NSLog(@"%@", error);
        return nil;
    }
}

- (NSDictionary*)getById:(NSInteger*)ident
{
    NSURL* url = [NSURL URLWithString:[NSString stringWithFormat:@"%@/%@", self.modelUrl, ident]];
    return [self HTTPRequest:url];
}

- (NSDictionary*)getAll
{
    NSURL* url = [NSURL URLWithString:[NSString stringWithFormat:@"%@", self.modelUrl]];
    return [self HTTPRequest:url];
}

- (void)dealloc
{
    [_modelUrl release];
//    [_responseData release];
//    [_responseDict release];
    [super dealloc];
}

@end

Edit: Now it isn’t crashing, but my local NSDictionary has a count of 0. I’m calling the following in -viewDidLoad in my controller:

RestModel* rm = [[RestModel alloc] initWithModel:@"user"];
self.dict = [rm getAll];
[rm release];

I planted NSLog of [self.dict count] throughout the controller. It is always 0. The RestModel rm is called, the functions are called (again more NSLogs), but no data. Any ideas?

  • 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-25T13:41:34+00:00Added an answer on May 25, 2026 at 1:41 pm
        [error release]; 
        [request release];
    

    Those should be auto-released objects, as you got them by convenience methods, so releasing them explicitly will make your application crash.

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

Sidebar

Related Questions

I'm trying to store a password in a file that I'd like to retrieve
I'm trying to store an xml serialized object in a cookie, but i get
I am trying to store more than 1 data item at a single index
I am trying to store a large amount of boolean information that is determined
I am trying to store/retrieve a value that is stored in the Application Settings.
I'm trying to create a python script that logs into JIRA using their REST
I'm trying to use SQL, REST or the Jira Api to find out what
I'm stuck trying to retrieve data from an associated model store. Allow me to
I am trying to store an xml value in my app.config file. The app.config
I'm trying to store the names of some variables inside strings. For example: Dim

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.