You can use them outside block just like any other variable.
In your current code this log will print nil, because code inside the block gets executed asynchronously, in this case - when the search results return.
If you want meaningful value from myObject
, you should really put your log inside the block, after myObject
assignment.
See the order of execution in comments:
__block PFObject *myObject = nil; //1
PFQuery *query = [PFQuery queryWithClassName:@"ClassName"]; //2
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error) { //3
if (objects.count) //5
myObject = [objects lastObject]; //6
}]; //7
NSLog(@"%@",myObject); //4