fromFunction static method

ObjCBlock<NSCollectionViewItem Function(Pointer<Void>, NSCollectionView, NSIndexPath)> fromFunction(
  1. NSCollectionViewItem fn(
    1. Pointer<Void>,
    2. NSCollectionView,
    3. NSIndexPath
    ), {
  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<
  NSCollectionViewItem Function(
    ffi.Pointer<ffi.Void>,
    NSCollectionView,
    NSIndexPath,
  )
>
fromFunction(
  NSCollectionViewItem Function(
    ffi.Pointer<ffi.Void>,
    NSCollectionView,
    NSIndexPath,
  )
  fn, {
  bool keepIsolateAlive = true,
}) =>
    objc.ObjCBlock<
      NSCollectionViewItem Function(
        ffi.Pointer<ffi.Void>,
        NSCollectionView,
        NSIndexPath,
      )
    >(
      objc.newClosureBlock(
        _ObjCBlock_NSCollectionViewItem_ffiVoid_NSCollectionView_NSIndexPath_closureCallable,
        (
          ffi.Pointer<ffi.Void> arg0,
          ffi.Pointer<objc.ObjCObject> arg1,
          ffi.Pointer<objc.ObjCObject> arg2,
        ) => fn(
          arg0,
          NSCollectionView.castFromPointer(arg1, retain: true, release: true),
          NSIndexPath.castFromPointer(arg2, retain: true, release: true),
        ).ref.retainAndAutorelease(),
        keepIsolateAlive,
      ),
      retain: false,
      release: true,
    );