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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T13:21:58+00:00 2026-06-13T13:21:58+00:00

I have the following class called ZipCode and a loadData method that successfully gets

  • 0

I have the following class called ZipCode and a loadData method that successfully gets data from a third party service and populates my local instantiated ZipCode class. The problem I am having is getting the populated values in this class into 5 local variables I can then pass on to my stored procedure which pulls back from the database the stores surrounding the entered zip code.

ZipCode.h

@interface ZipCodes : NSObject

@property (strong,nonatomic) NSString *city; //adminName2
@property (strong,nonatomic) NSString *stateAbbreviation; //adminCode1
@property (strong,nonatomic) NSString *postalCode; // postalCode
@property (strong,nonatomic) NSString *distance; //distance
@property (strong,nonatomic) NSString *country; // countryCode
@property (strong,nonatomic) NSString *stateName; //adminName1

-(id)initWithName:(NSString *)city stateAbbrev:(NSString *)stateAbbreviation postalCode:(NSString *)postalCode distanceFromGPSZip:(NSString *)distance country:(NSString *)country stateFullName:(NSString *)stateName;

@end

ZipCode.m

@implementation ZipCodes

-(id)initWithName:(NSString *)city stateAbbrev:(NSString *)stateAbbreviation postalCode:(NSString *)postalCode distanceFromGPSZip:(NSString *)distance country:(NSString *)country stateFullName:(NSString *)stateName {

if (self = [super init]) {

    _city = city;
    _stateAbbreviation = stateAbbreviation;
    _postalCode = postalCode;
    _distance = distance;
    _country = country;
    _stateName = stateName;
}

return self;
}

-(NSString *)description {

return [NSString stringWithFormat:@"City=%@, State=%@  Zip=%@ is %@ from the original zipCode queried", self.city, self.stateAbbreviation, self.postalCode, self.distance];
}

-(NSString *)postalCode {

return self.postalCode; // This is where I get a rather long loop...
}

@end

-(void) loadData:(NSString *)zipCode {

NSLog(@"GetSurroundingZipCodes is in loadData...");

self.zipCodes = [NSMutableArray array];

NSURL *url = nil;

NSLog(@"Get surrounding zip codes url is: %@", url);
NSString *zipCode = @"92675";
url = [NSURL URLWithString:[NSString stringWithFormat:@"http://api.geonames.org/findNearbyPostalCodesJSON?postalcode=%@&country=US&radius=10&username=frequentz", zipCode]];

NSURLRequest * urlRequest = [NSURLRequest requestWithURL:url];
NSError *error = nil;
NSURLResponse * response = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:urlRequest returningResponse:&response error:&error];

self.zipCodes = [NSMutableArray array];

id jsonObject = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments error:&error];

if (jsonObject != nil && error == nil) {

    NSLog(@"Successfully deserialized...");

    if ([jsonObject isKindOfClass:[NSDictionary class]]) {

        NSDictionary *deserializedDictionary = (NSDictionary *)jsonObject;
        NSLog(@"Deserialized JSON Dictionary = %@", deserializedDictionary);

        for (NSString* key in deserializedDictionary) {

            id value = [deserializedDictionary objectForKey:key];

            for (NSDictionary *item in value) {

                NSString *city = [item objectForKey:@"adminName2"];
                NSString *stateAbbreviation = [item objectForKey:@"adminCode1"];
                NSString *postalCode = [item objectForKey:@"postalCode"];
                NSString *distance = [item objectForKey:@"distance"];
                NSString *country = [item objectForKey:@"country"];
                NSString *stateName = [item objectForKey:@"stateName"];

                ZipCodes *zipCode = [[ZipCodes alloc] initWithName:city stateAbbrev:stateAbbreviation postalCode:postalCode distanceFromGPSZip:distance country:country stateFullName:stateName];

                [self.zipCodes addObject:zipCode];
            }
        }
    }
}
else if (error != nil){
    NSLog(@"An error happened while deserializing the JSON data.");
}

// Assign zip codes to first five _zipCode1..5 variables
for (int i = 1; i <= 5; i++) {

    if (i == 1) {
        // If I comment out the return of zipCode in the ZipCode.m file above the loop goes away and I get a string description that looks like this: self.zipCodes: City=San Francisco, State=CA  Zip=94123 is 1.59213 from the original zipCode queried at index: 1
        NSLog(@"self.zipCodes: %@ at index: %i", self.zipCodes[i], i);  

        // Here I get the following error:  -[ZipCodes objectForKey:]: unrecognized selector sent to instance
        _zipCode1 = [[self.zipCodes objectAtIndex:i] objectForKey:@"postalCode"];

    } else if (i == 2) {
        _zipCode2 = [[self.zipCodes objectAtIndex:i] objectForKey:@"Zip"];
    } //etc...//
}
}
  • 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-13T13:22:00+00:00Added an answer on June 13, 2026 at 1:22 pm

    Just remove:

    -(NSString *)postalCode {
    
    return self.postalCode; // This is where I get a rather long loop...
    }
    

    The loop you’re getting is because your getter is calling itself (self.postalCode just calls this method). Since you have a property you do not need to manually define a getter, it’s synthesized automatically for you.

    If for any reason you want to manually define the getter do something like this:

    -(NSString *)postalCode {
    
    return _postalCode;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following use case: There's a class called Template and with that
I have the following methods in my Authentication class that is called by my
I have the following method which is called when the value Edit Class... is
I have the following class called City that contains another class called Detail. public
I have the following problem: In my data model I have a class called
I have one class called Holder (holder.cs) that contain the following: string name; List<String>
I have the following code in a static class called Methods that is archived
I have the following classes: Class called House (which have data regarding the house
I have the following static method in an class called Article : public static
I have the following class called Tree that builds a simple tree class Tree

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.