0

I get this warning in Xcode

warning: Attempting to create USE_BLOCK_IN_FRAME variable with block that isn't in the frame.

Xcode redirect me to my NSStream

_naturStream = [[NSInputStream alloc] initWithData:natur];

It is random when it does this error, and my application crashes when it is triggered. Anyone tried similar problem ?

thanks

EDIT

in the appDelegate.h

@property (nonatomic, strong) NSInputStream *naturStream;

In the appDelegate.m:

  NSData *natur = [NSData dataWithContentsOfURL:[NSURL URLWithString:_locString]];
    
    _naturStream = [[NSInputStream alloc] initWithData:natur];
    
    [_naturStream open];
    
    
    
    if (_naturStream) {
    
        NSError *parseError = nil;
        id jsonObject = [NSJSONSerialization JSONObjectWithStream:_naturStream options:NSJSONReadingAllowFragments error:&parseError];        
        if ([jsonObject respondsToSelector:@selector(objectForKey:)]) {
            for (NSDictionary *natur in [jsonObject objectForKey:@"results"]) {
              
                _poi  = [[POI alloc]init];
                [_poi setTitle:[natur objectForKey:@"title"]];
                [_poi setLat:[[natur objectForKey:@"lat"]floatValue]];
                [_poi setLon:[[natur objectForKey:@"lng"]floatValue]];
                [_poi setDistance:[natur objectForKey:@"distance"]];
                [_poi setWebUrl:[natur objectForKey:@"webpage"]];
                
                [_naturArray addObject:_poi];
            }    
        }
    } 
    else {
        
        NSLog(@"Failed to open stream.");
    }
    
    [_naturStream close];
}

I realized that i forgot [_naturStream close] i don't know if it has solved the problem or not ?

EDIT

Another thing,.... I use a Thread for fetching the JSON data:

dispatch_queue_t jsonParsingQueue = dispatch_queue_create("jsonParsingQueue", NULL);
    
    // execute a task on that queue asynchronously
    dispatch_async(jsonParsingQueue, ^{
        [self parseJSON];


    dispatch_async(dispatch_get_main_queue(), ^{
        
        [_kortvisning updateAnno];
        [visListe updateList];
            
             });
    });
    
    // release the dispatch queue
    dispatch_release(jsonParsingQueue);
Community
  • 1
  • 1
Roskvist
  • 1,030
  • 3
  • 14
  • 24
  • Ok - new suggestion - check your linker settings? http://stackoverflow.com/questions/7111541/exc-bad-access-when-copying-or-retaining-block/7115171#7115171 – Scott Corscadden Mar 03 '12 at 12:52

1 Answers1

1

Sounds like you're using ARC - if _naturStream is an instance variable for an objective C class, you might need to pull it out and add a __block reference so that ARC knows the scope correctly - but I'm guessing because I don't see how the block is used with the NSInputStream (if you post that part we might know). A good bit is here: http://nachbaur.com/blog/using-gcd-and-blocks-effectively

-- edit --

Ok, now that you posted the rest, I bet it has to do with the _kortvisning and visListe variables. I think you want to pull those out right after you create your queue something like

__block KortVisning *localKortVisning = _kortvisning;
__block NSMutableArray *localVisListe = visListe;

Then access those directly from your final completion handler you're sending back to the main queue.

Scott Corscadden
  • 2,831
  • 1
  • 25
  • 43
  • Just got the error ... So it was not the need for stream close – Roskvist Mar 01 '12 at 14:02
  • Okay.. I have changed it... will post if i get the error again :) took some time last time – Roskvist Mar 02 '12 at 07:46
  • Hello again... After i used the code above i tried checking if(nature != nil) It i was nil it throws an alertView saying the data is unavailable... I tried nature = nil before adding the alertView and that resulted in that BLOCK error. So now i am sure that that error will not make my app crash anymore... But i got that error just now (Not BLOCK But natur = nil), when the data should be available.. And we wondering if i have forgot something ? :S – Roskvist Mar 02 '12 at 13:10
  • Hmm - are you sure that the file exists? What does _locString equal? (I'm assuming that it's on the device, not a URL over the network). Can you see the file on your file system? Both simulator and actual device allow you to inspect the filesystem. – Scott Corscadden Mar 23 '12 at 13:16