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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T17:12:08+00:00 2026-06-07T17:12:08+00:00

Ok this is annoying me. I have the following code: weatherAddress = [NSString stringWithFormat:@http://google.com];

  • 0

Ok this is annoying me. I have the following code:

weatherAddress = [NSString stringWithFormat:@"http://google.com"];
    weatherUrl = [NSURL URLWithString:weatherAddress];
    weatherContents = [NSString stringWithContentsOfURL:weatherUrl encoding:NSASCIIStringEncoding error:nil];

if ([viewer.request.URL.relativeString isEqualToString:weatherContents]) {
   //do stuff
}

but when it runs, it sometimes throws a bad access. When i say sometimes I mean usually 50% of the time. What am I doing wrong?

  • 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-07T17:12:11+00:00Added an answer on June 7, 2026 at 5:12 pm

    How about this, assuming weatherContents is defined in the class:

    weatherAddress = [NSString stringWithFormat:@"http://google.com"];
    weatherUrl = [NSURL URLWithString:weatherAddress];
    weatherContents = [NSString stringWithContentsOfURL:weatherUrl encoding:NSASCIIStringEncoding error:nil];
    
    [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(checkIfWeatherReceived) userInfo:nil repeats:NO];
    

    then create a method called checkIfWeatherReceived like so:

    -(void) checkIfWeatherReceived
    {
        if(weatherContents)
        {
            if ([viewer.request.URL.relativeString isEqualToString:weatherContents]) {
                //do stuff
            }
        } else {
            [NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(checkIfWeatherReceived) userInfo:nil repeats:NO];
        }
    }
    

    I really don’t like using stuff that will lock up your interface if your connection drops out, so I would refrain from just “making it wait” or something. This will check every half a second if the weather data has been grabbed. If you want it to check faster just change the TimeInterval. You may want it to be really really fast like .01 or something if you are not finding very much delay in the data. You should also think about what will happen if the connection is lost and you never get the data, unless you have already accounted for that. I have not tested this, but I think it should work out, assuming all of your pieces are part of the class and not local to a method. I would also probably break out the actual work from checkIfWeatherReceived into another method, instead of just placing it in the if(weatherContents) true area.

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

Sidebar

Related Questions

I have this annoying problem, that Im pretty sure happens to all of you
i have this annoying problem with my site where, when you click on a
I have this annoying method which pop up a MessageBox. So when I try
I have been having this annoying problem when trying to implement a picture gallery
This is annoying - I know how I'd do it in web... I have
I find this syntax astoundingly annoying. Every time I rename my class, I have
I have the following elements in my schema: <xs:schema attributeFormDefault=unqualified elementFormDefault=qualified xmlns:xs=http://www.w3.org/2001/XMLSchema> <xs:complexType name=optimizeModelBase>
I have the following code I am trying to fix foreach (System.IO.DirectoryInfo dir in
I have the following code in an equals method. public boolean equals(Object o){ if
I have the following snippet of code. abstract class MrParent { public function __construct()

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.