cupertino_ffi 0.1.4 copy "cupertino_ffi: ^0.1.4" to clipboard
cupertino_ffi: ^0.1.4 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 (command-line tools).

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"
  • Examples:
    • CFArray
    • CFData
    • CFDictionary
    • CFError
    • CFString
    • etc.
  • 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 #

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 Objective-C documentation "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 APIs that return ARC pointers, you need to call arcPush and arcPop in the following way:

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 reference counting pointer, 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 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
30%
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