Question

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);
Was it helpful?

Solution

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top