Skip to main content

Crate apple_objc_sys

Crate apple_objc_sys 

Source
Expand description

Minimal ObjC runtime FFI for Apple framework crates.

Provides the raw ObjC runtime symbols (objc_msgSend, objc_getClass, sel_registerName) plus ergonomic helper macros so framework crates can call ObjC methods directly from Rust — no .m files, no cc build step.

§Example

use apple_objc_sys::*;

unsafe {
    let cls = class!(b"NSProcessInfo");
    let info: Id = msg_send![cls, processInfo];
    let count: isize = msg_send![info, processorCount];
}

§License

GPL-3.0 — Copyright © 2025 Eugene Hauptmann

Macros§

class
Look up an ObjC class by name (null-terminated byte string).
msg_send
Send an ObjC message. Returns Id by default.
msg_send_t
Send an ObjC message that returns a typed non-Id value (bool, isize, f64, etc.).
msg_send_void
Void-returning ObjC message send.
sel
Register / look up an ObjC selector (null-terminated byte string).

Constants§

K_CF_ALLOCATOR_DEFAULT
K_CF_STRING_ENCODING_UTF8
NIL
NULL object.

Statics§

kCFBooleanFalse
kCFBooleanTrue
kCFTypeDictionaryKeyCallBacks
kCFTypeDictionaryValueCallBacks

Functions§

CFDataCreate
CFDataGetBytePtr
CFDataGetLength
CFDictionaryCreate
CFRelease
CFRetain
CFStringCreateWithBytes
CFStringGetCString
CFStringGetCStringPtr
CFStringGetLength
cfdict
Build a CFDictionaryRef from parallel key/value slices.
dlsym_global
Look up a global symbol by name via dlsym(RTLD_DEFAULT, name).
global_string_const
Read a global NSString* / CFStringRef constant by symbol name. Many Apple framework constants (e.g. kSecClass) are pointers to CFStringRef — this dereferences the pointer.
nsstring
Create an autoreleased NSString from a Rust &str.
nsstring_to_buf
Write an NSString* into a (buf, len) pair, returning bytes written or -1.
nsstring_to_string
Read an NSString* (toll-free bridged CFStringRef) into a Rust String.
objc_getClass
objc_msgSend
objc_msgSend_stret
objc_msgSend variant for stret on x86_64 (structs > 16 bytes).
sel_registerName

Type Aliases§

CFAllocatorRef
CFDataRef
CFDictionaryRef
CFIndex
CFStringRef
CFTypeRef
Class
Opaque ObjC class pointer.
Id
Opaque ObjC object pointer.
Sel
Opaque ObjC selector pointer.