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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T14:53:33+00:00 2026-05-22T14:53:33+00:00

What I would like to do is take the [self getYear] method which is

  • 0

What I would like to do is take the [self getYear] method which is predefined and returns an NSString in the form of a year (i.e. 1995), and then take that number and match it to which year it actually is, and set that to a URL variable, theClassyear. When this project is run, i have this as part of a setup method in -viewWillAppear and when I pull up the view (this is in a tab bar controller fyi) then I get either an NSURL error 101 or error -999. The [self getYear] method takes it’s string from a NSUserDefaults string that is set by a UIPicker in a different view pushed by the controller. Like I said, when I first open the view and this method runs I get the correct result from the first NSLog, but then it runs through my if statements and ends up using the else statement which sets my NSURL that is supposed to be returned to null (according to my NSLog). Later on in the code I have another NSLog that prints the [self getYear] result again and that gives me the right number also. somehow my if-then logic is not running through correctly and I would love advice on what I may be doing wrong. Thanks in advance!!! 🙂

-(NSURL *)theClassYear{

NSURL *theClassYear = [[NSURL alloc] init];
NSLog(@"the user default loaded for the year is: %@",[self getYear]);

if ([self getYear] == @"1995") {
    theClassYear = [NSURL URLWithString:@"http://www.facebook.com/group.php?gid=35443264449"];
}
else if ([self getYear] == @"1996"){
    theClassYear = [NSURL URLWithString:@"http://www.facebook.com/group.php?gid=50371222704"];
}
else if ([self getYear] == @"1997"){
    theClassYear = [NSURL URLWithString:@"http://www.facebook.com/group.php?gid=101880069858690"];
}
else if ([self getYear] == @"1998"){
    theClassYear = [NSURL URLWithString:@"http://www.facebook.com/group.php?gid=98761155252"];
}
else if ([self getYear] == @"1999"){
    theClassYear = [NSURL URLWithString:@"http://www.facebook.com/group.php?gid=34955119113"];
}
else if ([self getYear] == @"2000"){
    theClassYear = [NSURL URLWithString:@"http://www.facebook.com/group.php?gid=41438241821"];
}
else if ([self getYear] == @"2001"){
    theClassYear = [NSURL URLWithString:@"http://www.facebook.com/group.php?gid=44108047608"];
}
else if ([self getYear] == @"2002"){
    theClassYear = [NSURL URLWithString:@"http://www.facebook.com/group.php?gid=98700780436"];
}
else if ([self getYear] == @"2003"){
    theClassYear = [NSURL URLWithString:@"http://www.facebook.com/group.php?gid=36811255052"];
}
else if ([self getYear] == @"2004"){
    theClassYear = [NSURL URLWithString:@"http://www.facebook.com/group.php?gid=40331531709"];
}
else if ([self getYear] == @"2005"){
    theClassYear = [NSURL URLWithString:@"http://www.facebook.com/group.php?gid=97724430117"];
}
else if ([self getYear] == @"2006"){
    theClassYear = [NSURL URLWithString:@"http://www.facebook.com/group.php?gid=50868469971"];
}
else if ([self getYear] == @"2007"){
    theClassYear = [NSURL URLWithString:@"http://www.facebook.com/group.php?gid=38506528654"];
}
else if ([self getYear] == @"2008"){
    theClassYear = [NSURL URLWithString:@"http://www.facebook.com/group.php?gid=55466866222"];
}
else if ([self getYear] == @"2009"){
    theClassYear = [NSURL URLWithString:@"http://www.facebook.com/group.php?gid=105187085612"];
}
else if ([self getYear] == @"2010"){
    theClassYear = [NSURL URLWithString:@"http://www.facebook.com/group.php?gid=39303927757"];
}
else if ([self getYear] == @"2011"){
    theClassYear = [NSURL URLWithString:@"http://www.facebook.com/group.php?gid=281837582821"];
}
else if ([self getYear] == @"2012"){
    theClassYear = [NSURL URLWithString:@"http://www.facebook.com/group.php?gid=79162636609"];
}
else if ([self getYear] == @"2013"){
theClassYear = [NSURL URLWithString:@"http://www.facebook.com/home.php?sk=group_161338720557447"];
}
else if ([self getYear] == @"2014"){
    theClassYear = [NSURL URLWithString:@"http://www.facebook.com/home.php?sk=group_125352334187406"];
}
else {
    NSLog(@"no matches");
}    

NSLog(@"the url for the year you chose is: %@",theClassYear);

return theClassYear;
[theClassYear release];

}

  • 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-22T14:53:34+00:00Added an answer on May 22, 2026 at 2:53 pm

    When you use == on objects such as NSString in Objective-C, you are not comparing the values of the objects, but the memory address of the object.* If you have two strings, and you want to see whether their contents are the same, you must, as Mahesh mentioned, use isEqualToString:, which does the correct comparison.

    There are a couple of other things that can improved in your code. First, you are leaking an NSURL. You first create one with

    NSURL *theClassYear = [[NSURL alloc] init];
    

    and then you ignore it and create another one in one of the branches of your if:

    theClassYear = [NSURL URLWithString:@"http://www.facebook.com/group.php?gid=35443264449"];
    // This creates a new NSURL instance and leaks the old one.
    

    To fix this, simply remove the initial assignment and make it a declaration:

    NSURL * theClassYear;   // You will assign to this name later, in a branch
    

    Next, as Mahesh also pointed out, once you say return in a method, nothing past that line gets executed, so your [theClassYear release] does not occur. In this case, it’s actually unnecessary, too.** The object that you get back from URLWithString: is autoreleased, which in this case is exactly what you want.

    Finally, please do take Rexeisen’s advice about putting all those strings into a dictionary. It will make your code much easier to read and more maintainable.


    *Unlike interpreted languages such as Python, Perl, or PHP, or compiled languages with operator overloading such as C++.
    **In fact, if it were running it would cause a crash due to overreleasing.

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

Sidebar

Related Questions

I would like to take a field and replace all characters that are not
What I would like to take ownership of a hid device that may already
I have two ICollection s of which I would like to take the union.
I would like to take a pascal-cased string like CountOfWidgets and convert it into
I would like to take a stack of images (or potentially an array of
I would like to take a string representation of a set and parse it.
Using Flex 3, I would like to take an image snapshot such as this:
Using sql server 2000, I would like to take my production data and put
I am working on a project using Groovy, and I would like to take
I would like to have an iframe take as much vertical space as it

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.