fromFunction static method

ObjCBlock<NSDictionary Function(NSDictionary)> fromFunction(
  1. NSDictionary fn(
    1. NSDictionary
    ), {
  2. bool keepIsolateAlive = true,
})

Creates a block from a Dart function.

This block must be invoked by native code running on the same thread as the isolate that registered it. Invoking the block on the wrong thread will result in a crash.

If keepIsolateAlive is true, this block will keep this isolate alive until it is garbage collected by both Dart and ObjC.

Implementation

static objc.ObjCBlock<objc.NSDictionary Function(objc.NSDictionary)> fromFunction(
  objc.NSDictionary Function(objc.NSDictionary) fn, {
  bool keepIsolateAlive = true,
}) => objc.ObjCBlock<objc.NSDictionary Function(objc.NSDictionary)>(
  objc.newClosureBlock(
    _ObjCBlock_NSDictionary_NSDictionary_closureCallable,
    (ffi.Pointer<objc.ObjCObject> arg0) =>
        fn(objc.NSDictionary.castFromPointer(arg0, retain: true, release: true)).ref.retainAndAutorelease(),
    keepIsolateAlive,
  ),
  retain: false,
  release: true,
);