Returning block from method with a block parameter

Hi,

Is this ok ?

namespace BlocksConsoleApplication;

uses
Foundation;

type

CompletionBlock = block(value:Integer);

Program = class
public

class method SomeBlock(completion:CompletionBlock): block;
begin
  
  exit method begin
    
    completion(4);
    
    NSLog('In block');
    
  end;
end;


class method Main(args: array of String): Int32;
begin
  
  var mylock := new Object;
  var someList := new NSMutableArray<Integer>;
  
  var completionBlock:CompletionBlock := method(value:Integer); begin
    locking mylock do begin
      someList.AddObject(value);
    end;
  end;
  
  var blockObj := SomeBlock(completionBlock);
  /*
  var blockObj := method begin

    completionBlock(4);
    
    NSLog('In block');
    
  end;
  */

  
  var innerExecutionBlock: NSBlockOperation := NSBlockOperation.blockOperationWithBlock(blockObj);
  /*
  innerExecutionBlock.completionBlock := method begin
      NSLog('completion block');
    end;
  */
  var innerQueue: NSOperationQueue := new NSOperationQueue();
  innerQueue.addOperation(innerExecutionBlock);
  innerQueue.waitUntilAllOperationsAreFinished;
  
  NSLog('Finished');
end;

end;

end.

If I return the block inline as in the commented out code then it works but if I return the block from the method it doesnt. It looks like something is being release too many times.

Cheers,
John

Thanks, logged as bugs://81815

Looks like a bug but I’ll have to investigate.

Hi,
I don’t suppose you have had the time to determine if this a bug or not ?

Ive been trying to refactor some code and Im not sure if I should abandon what I was doing.

Cheers,
John

This should work yes so it’s a bug for sure; I’m just not sure when I get around to fix it. If you do have a workaround I’d use it for now. I will let you know when it’s fixed though.

bugs://81815 got closed with status fixed.