23 releases

0.6.0 Jan 22, 2025
0.5.2 May 21, 2024
0.5.1 Apr 17, 2024
0.5.0 Dec 3, 2023
0.3.0-alpha.4 Nov 22, 2021

#31 in macOS and iOS APIs

Download history 125797/week @ 2024-10-30 132548/week @ 2024-11-06 126449/week @ 2024-11-13 116132/week @ 2024-11-20 113366/week @ 2024-11-27 124213/week @ 2024-12-04 121795/week @ 2024-12-11 103024/week @ 2024-12-18 88628/week @ 2024-12-25 98862/week @ 2025-01-01 133561/week @ 2025-01-08 132333/week @ 2025-01-15 141222/week @ 2025-01-22 145074/week @ 2025-01-29 196080/week @ 2025-02-05 344483/week @ 2025-02-12

848,717 downloads per month
Used in 2,602 crates (208 directly)

MIT license

1MB
17K SLoC

objc2

Latest version License Documentation CI

Objective-C interface and runtime bindings in Rust.

Most of the core libraries and frameworks that are in use on Apple systems are written in Objective-C; this crate enables you to interact with those.

This README is kept intentionally small in an effort to consolidate the documentation, see the Rust docs for more details.

This crate is part of the objc2 project, see that for related crates.


lib.rs:

Objective-C interface and runtime bindings

Quick links:

Objective-C was the standard programming language on Apple platforms like macOS, iOS, iPadOS, tvOS and watchOS. It is an object-oriented language centered around "sending messages" to its instances - this can for the most part be viewed as a function call.

It has since been superseded by Swift, but most of the core libraries and frameworks that are in use on Apple systems are still written in Objective-C, and hence we would like the ability to interact with these using Rust. This crate enables bi-directional interop with Objective-C, in as safe a manner as possible.

Example

Most of the time, you'll want to use one of [the framework crates], which contain bindings to CoreFoundation, Foundation, AppKit, Metal, UIKit, WebKit and so on.

In this example we're going to be using objc2-foundation and objc2-app-kit to create a simple GUI application that displays a "Hello World" label.

$ # Add the necessary crates to your project.
$ cargo add objc2 objc2-foundation objc2-app-kit

[the framework crates]: crate::topics::about_generated
[`objc2-foundation`]: https://docs.rs/objc2-foundation
[`objc2-app-kit`]: https://docs.rs/objc2-app-kit


## Crate features

This crate exports several optional cargo features, see [`Cargo.toml`] for
an overview and description of these.

The features in the framework crates are described [here][cr-feat]. Note
that if you're developing a library for others to use, you might want to
reduce compile times by disabling default features and only enabling the
features you need.

[cr-feat]: crate::topics::about_generated::cargo_features


## Supported operating systems

- macOS: `10.12-15.2`
- iOS: `10.0-18.2` (includes iPadOS and Mac Catalyst)
- tvOS: `10.0-18.2`
- watchOS: `5.0-11.2`
- visionOS: `1.0-2.2`

The minimum versions are the same as those supported by `rustc`. Higher
versions will also work, but the framework crates will not have bindings
available for newer APIs.

The framework bindings are generated from the SDKs in Xcode 16.2. The
Xcode version will be periodically updated.

Note that the bindings are currently generated in a very macOS-centric, so
they may try to use types from AppKit, even on iOS, see for example
[#637](https://github.com/madsmtm/objc2/issues/637).

The bindings _can_ also be used on Linux or *BSD utilizing the
[GNUstep Objective-C runtime](https://github.com/gnustep/libobjc2), see
the [`ffi`] module for how to configure this, but this is very much
second-class.


## Minimum Supported Rust Version (MSRV)

The _currently_ minimum supported Rust version is `1.71` (to be able to
use `extern "C-unwind"` functions); this is _not_ defined by policy,
though, so it may change in at any time in a patch release.

Help us define a policy over in [#203].

[#203]: https://github.com/madsmtm/objc2/issues/203

Dependencies