Available on crate feature foundation only.
Expand description

Bindings to the Foundation framework.

This is the std equivalent for Objective-C, containing essential data types, collections, and operating-system services.

See Apple’s documentation.

Philosophy

The Foundation framework is huge! If we aspired to map every API it exposes (a lot of it is just helper methods to make Objective-C more ergonomic), this library would never be finished. Instead, our focus lies on conversion methods, to allow easily using them from Rust.

If you find some API that an object doesn’t expose (but should), we gladly accept pull requests. If it is something that is out of scope, these objects implement the Message trait, so you can always just manually call a method on them using the msg_send! family of macros.

Use of Deref

objc2::foundation uses the Deref trait in a bit special way: All objects deref to their superclasses. For example, NSMutableArray derefs to NSArray, which in turn derefs to NSObject.

Note that this is explicitly recommended against in the documentation and the Rust Design patterns book (see those links for details).

Due to Objective-C objects only ever being accessible behind pointers in the first place, the problems stated there are less severe, and having the implementation just means that everything is much nicer when you actually want to use the objects!

All objects also implement AsRef and AsMut to their superclass, and can be used in Id::into_super, so if you favour explicit conversion, that is a possibility too.

Re-exports

pub use crate::ffi::NSInteger;
pub use crate::ffi::NSUInteger;

Structs

A point in a two-dimensional coordinate system.

The location and dimensions of a rectangle.

A two-dimensional size.

A marker type taken by functions that can only be executed on the main thread.

An immutable ordered collection of objects.

A string that has associated attributes for portions of its text.

A representation of the code and resources stored in a bundle directory on disk.

A static byte buffer in memory.

Information about an error condition including a domain, a domain-specific error code, and application-specific information.

A special condition that interrupts the normal flow of program execution.

A growable ordered collection of objects.

A mutable string that has associated attributes.

A dynamic byte buffer in memory.

A mutable collection of objects associated with unique keys.

A growable unordered collection of unique objects.

A dynamic plain-text Unicode string object.

An object wrapper for primitive scalars.

A collection of information about the current process.

TODO.

An immutable unordered collection of unique objects.

An immutable, plain-text Unicode string object.

A thread of execution.

NSUUIDNon-macos_10_7

A universally unique value.

A container wrapping any encodable type as an Obective-C object.

A type used to identify and manage memory zones.

Enums

Constants that indicate sort order.

Constants

A value indicating that a requested item couldn’t be found or doesn’t exist.

Traits

Functions

Whether the current thread is the main thread.

Whether the application is multithreaded according to Cocoa.

Type Definitions

The basic type for all floating-point values.

Attributes that you can apply to text in an attributed string.

A point in a Cartesian coordinate system.

A rectangle.

A two-dimensional size.

A number of seconds.