cupertino_ffi 0.1.5 copy "cupertino_ffi: ^0.1.5" to clipboard
cupertino_ffi: ^0.1.5 copied to clipboard

discontinued
outdated

A large number of APIs by Apple made available with 'dart:ffi'. Contains helpers for using any Objective-C library.

Pub Package

Overview #

This package enables Dart developers to use a large number Objective-C APIs. The package uses dart:ffi and the APIs are generated with ffi_tool.

Most Flutter developers should not use this package. It's usually a better idea to write a Flutter plugin than use this package. Flutter plugins are less likely to contain memory management bugs, they are automatically isolated from the UI event loop, they support all APIs, and the development experience is just a lot better.

The advantages of this package are automatic generation of APIs (no need to write message passing code) and support for non-Flutter applications.

If you decide to use this package, you must follow the correct reference counting patterns. The patterns are documented below.

Github project #

  • Github project
  • The project appreciates bug reports, suggestions, and general feedback.

Core foundation #

  • Documentation: developer.apple.com
  • Import "package:cupertino_ffi/core_foundation.dart"
  • Note that Foundation types (NSString, etc.) and Core Foundation types (CFString, etc.) are "toll-free" bridged types. This means that Pointer<CFString> can be used as Pointer<NSString> and vice-versa.

Generated libraries #

Dartdoc can be found here.

Name Documentation Import Description
CloudKit docs "package:cupertino_ffi/cloudkit.dart" Cloud-based storage.
Contacts docs "package:cupertino_ffi/contacts.dart" Contacts.
Core Data docs "package:cupertino_ffi/core_data.dart" Loading and storing data.
Core Location docs "package:cupertino_ffi/core_location.dart" Geographical location.
Core ML docs "package:cupertino_ffi/core_ml.dart" Machine learning.
Core Spotlight docs "package:cupertino_ffi/core_spotlight.dart" Search.
Core WLAN docs "package:cupertino_ffi/core_wlan.dart" WLAN.
EventKit docs "package:cupertino_ffi/eventkit.dart" Calendar events.
Foundation docs "package:cupertino_ffi/foundation.dart" Essential APIs.
Multipeer Connectivity docs "package:cupertino_ffi/multipeer_connectivity.dart" Peer-to-peer connectivity.
Natural Language docs "package:cupertino_ffi/natural_language.dart" Natural language processing (NLP).
Objective-C runtime docs "package:cupertino_ffi/objective_c.dart" Objective-C internals.
PassKit docs "package:cupertino_ffi/passkit.dart" Apple Pay and Apple Wallet.
PreferencePanes docs "package:cupertino_ffi/preferencepanes.dart" System preferences.
Security docs "package:cupertino_ffi/security.dart" Keychain, cryptography, authentication.
Speech docs "package:cupertino_ffi/speech.dart" Speech recognition.
Social docs "package:cupertino_ffi/social.dart" Social media.
StoreKit docs "package:cupertino_ffi/storekit.dart" App Store.
Vision docs "package:cupertino_ffi/vision.dart" Computer vision.
WebKit docs "package:cupertino_ffi/webkit.dart" Browser engine.

Want to add a library? Create an issue!

Memory management patterns #

Calling APIs that return ARC pointers #

If you call any API that returns a reference-counter pointer, you need to call arcPush and arcPop like in the following example:

String example() {
    // Push a new ARC frame.
    arcPush();
    try {
      Pointer pointer = CFDictionary.fromDart({"key": "value"});
      return "some return value";
    } finally {
      // Pop the topmost ARC frame.
      arcPop();
    }
}

Returning ARC pointers #

If you return a pointer to reference counted value, you must call function 'arcReturn', which inserts the pointer into caller's reference counting frame and increments the reference count (so it will 2 before 'arcPop').

Example:

Pointer<CFDictionary> example() {
    arcPush();
    try {
      final result = CFDictionary.fromDart({"key": "value"});
      return arcReturn(result);
    } finally {
      arcPop();
    }
}

Storing ARC pointer #

You need to ensure that arcFieldGet is invoked in the getter and arcFieldSet is invoked in the setter.

import 'package:cupertino_ffi/core_foundation.dart';

Pointer<CFString> _field;

Pointer<CFString> get field => arcFieldGet(_field);

set field(Pointer<CFString> newValue) {
  _field = arcFieldSet(_field, newValue);
}
3
likes
0
pub points
0%
popularity

Publisher

unverified uploader

A large number of APIs by Apple made available with 'dart:ffi'. Contains helpers for using any Objective-C library.

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

ffi, meta

More

Packages that depend on cupertino_ffi