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