p-hatan/ mirror

pub repository

mirror.p-hatan.ir

objective_c

1.0.0

A library to access Objective C from Flutter that acts as a support library for package:ffigen.

Download archive

Readme

Build Status Coverage Status pub package package publisher

objective_c

A library to access Objective C from Flutter that acts as a support library for package:ffigen.

This library isn't very useful on its own. Typically it is used while interoperating with an Objective C library created by package:ffigen. See https://pub.dev/packages/ffigen

For general information about interop with Objective C, see https://dart.dev/guides/libraries/objective-c-interop

Memory management

Objective C and Dart use different styles of memory management. Dart is garbage collected, while Objective C uses reference counting. This difference is a common cause of bugs when interoperating between the two languages.

Memory management issues typically manifest as seg faults, which can be hard to debug as they often have no useful stack trace. The most common issue is use after free errors, where a Dart object is constructed to wrap an Objective C object that has already been destroyed. To debug these issues, try running your program with asserts enabled. When the Dart wrapper object is created or destroyed, an assert checks that the Objective C object still exists, which should provide a much more useful stack trace.

References are automatically retained when the Dart wrapper object is created, and released when the Dart object is garbage collected. But to fix a reference counting issue, it may occasionally be necessary to manually control the ref count. The ref count of the Objective C object can be controlled from Dart by the retain and release options in the Dart wrapper object constructors, and by the retainAndReturnPointer() and release() methods.

Changelog

1.0.0

  • Move sharable code from ffigen's generated code into this package, including ObjCObjectBase, and ObjCBlockBase, as well as the core Objective C runtime functions (except objc_msgSend, which is library specific).
  • Move core ObjC classes such as NSString into this package.
  • Delete Dart functions associated with ObjC closure blocks when the block is destroyed. Fixes https://github.com/dart-lang/native/issues/204
  • Improve debuggability of memory management errors.

Installing

export PUB_HOSTED_URL=https://pub.mirror.p-hatan.ir
flutter pub add objective_c
pubspec.yaml
# Copyright (c) 2024, the Dart project authors.  Please see the AUTHORS file
# for details. All rights reserved. Use of this source code is governed by a
# BSD-style license that can be found in the LICENSE file.

name: objective_c
description: "A library to access Objective C from Flutter that acts as a support library for package:ffigen."
version: 1.0.0
repository: https://github.com/dart-lang/native/tree/main/pkgs/objective_c

topics:
  - interop
  - ffi
  - objective-c
  - codegen

environment:
  sdk: '>=3.3.0 <4.0.0'
  flutter: '>=3.3.0'

dependencies:
  flutter:
    sdk: flutter
  ffi: ^2.1.0
  plugin_platform_interface: ^2.0.2
  yaml: ^3.1.0

dev_dependencies:
  coverage: ^1.8.0
  ffigen: ^12.0.0
  flutter_test:
    sdk: flutter
  flutter_lints: ^3.0.0
  test: ^1.21.1

dependency_overrides:
  ffigen:
    path: ../ffigen/

flutter:
  plugin:
    platforms:
      ios:
        ffiPlugin: true
      macos:
        ffiPlugin: true

Version history

VersionPublishedArchiveSHA-256
1.0.02024-05-09T00:33:50.115047ZDownloadde30e81362adda5c43cd1b867158480ab28cf2158d4ef304c527a369f9959e15
1.0.12024-05-15T21:59:36.402563ZDownload32fb4ae9525491f83248272b52c80c16569fe7d5e9c157b0ff5275033212b697
1.1.02024-07-18T01:04:52.895023ZDownload77c341fce45bb3865a7bc3ddee4201605799e3de2f7af200e8dae26369d210ea
2.0.02024-09-06T08:13:40.416219ZDownload7ad3b1e4478812f8d642af1fe4698f86310ebec1248ba87e2a8fe74d2412731e
3.0.02024-10-21T21:21:05.275452ZDownloadc8467f3b067a3867c4876210b2fa65a57d117b5667ac158df5991804b0912673
4.0.02024-11-15T02:43:11.084758ZDownloada1fcb5df4501bb40651880199b868465e24d8b9677b3636f03a867edf9a8f420
4.1.02025-01-15T02:27:58.218149ZDownload62e79ab8c3ed6f6a340ea50dd48d65898f5d70425d404f0d99411f6e56e04584
5.0.02025-02-12T02:31:04.687417ZDownloadb6defaa81568bb299957b8584bd7fe400177634c7d4f1cc76edcb916296cba4b
6.0.02025-02-17T22:54:40.239060ZDownload39cc952b20c86686838d6bd8224b265d283ea1c8dfa5d14949bd15e322195b0e
7.0.02025-03-11T02:21:18.940059ZDownload49e569fac1202d7fee1655fbbdfbf228840e11416be592bce2a6797b23de8231
7.1.02025-04-08T22:31:19.351790ZDownload9f034ba1eeca53ddb339bc8f4813cb07336a849cd735559b60cdc068ecce2dc7
8.0.02025-05-19T00:02:26.870654ZDownload64e35e1e2e79da4e83f2ace3bf4e5437cef523f46c7db2eba9a1419c49573790
8.1.02025-07-22T00:23:53.069672ZDownload87103d96b19be76dc34b5ef859fecae78561d49779d5480b73c23b4dec8b9ec4
9.0.0-dev.02025-09-02T13:53:12.129438ZDownloade8955e9fa1ba06bfa03fb30a8a093e599778fbb84e88e0ec7cb22695da9b1d04
9.0.02025-11-07T01:07:12.776311ZDownloadeff755a5da5948e55b85b95bf0e4494fe8d3ffdc6e87a9544c92b4e8094abc1e
9.0.0+12025-11-07T04:18:12.394268ZDownloadd8e589a70ad743902771e52abda620d5bdc8b67e03128a81517b400098e82dd4
9.1.02025-11-19T00:39:12.794346ZDownload1f81ed9e41909d44162d7ec8663b2c647c202317cc0b56d3d56f6a13146a0b64
9.2.02025-11-25T00:07:39.782534ZDownload3d88b0d084eda819fa5302ec892f0d42e80945495c3fc204b57eb7ebb1440106
9.2.12025-11-25T23:30:00.410295ZDownloadc12701c978eacda8d8a9be1469f005e26bf16a903945982b94f77d7a9dbeea45
9.2.22025-12-17T22:40:38.911064ZDownload55eb67ede1002d9771b3f9264d2c9d30bc364f0267bc1c6cc0883280d5f0c7cb
9.2.32026-01-20T23:06:44.914901ZDownload9922a1ad59ac5afb154cc948aa6ded01987a75003651d0a2866afc23f4da624e
9.2.42026-01-23T02:57:41.433355ZDownload7fd0c4d8ac8980011753b9bdaed2bf15111365924cdeeeaeb596214ea2b03537
9.2.52026-01-29T00:50:04.184336ZDownload983c7fa1501f6dcc0cb7af4e42072e9993cb28d73604d25ebf4dab08165d997e
9.3.02026-02-06T04:02:40.689426ZDownload100a1c87616ab6ed41ec263b083c0ef3261ee6cd1dc3b0f35f8ddfa4f996fe52
9.4.02026-05-20T01:46:47.940867ZDownload02f4ff97ac95fa4abe561242eb033239e08e8903a46eaecf61b047761b89fe1f
9.4.12026-05-22T00:34:46.349406ZDownload6cb691c686fa2838c6deb34980d426145c2a5d537491cb83d463c33cdbc726ed
9.5.02026-07-27T01:11:38.214932ZDownloadb7fb95a6d9a4f009edd63dc5ac69f07420b23a16161c6dd8660290b59c602e8e
9.6.02026-08-20T01:19:06.485757ZDownloadad56fd53a78ff6b1472fa59ff2a4e8b8ccabafc586fc263a1dfad0b99b5553e3
9.6.12026-09-15T00:38:46.337201ZDownload2f9a00fff06cc27846da6e8bcda5e64c41a1ea656dcc4dc355ac717f8a272413
9.6.22026-10-01T02:53:11.198077ZDownload5c80c2ad6e2c0397de5db38c6d653e69616a3397e13aa7633bf39eb668f2041b

Dependencies

ffi "^2.1.0"

flutter { "sdk": "flutter" }

plugin_platform_interface "^2.0.2"

yaml "^3.1.0"