Crate icrate

Source
Expand description

§Bindings to Apple’s frameworks

icrate is an autogenerated interface to Apple’s Objective-C frameworks like AppKit, Foundation, Metal, WebKit, and so on.

The bindings currently contain very little documentation, you should view Apple’s developer documentation for detailed information about each API. (There are plans for importing that documentation here).

§Use of Deref

icrate 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.

§Rust vs. Objective-C types

A quick overview of some types you will encounter often in Objective-C, and their approximate Rust equivalent.

Objective-C(approximately) equivalent Rust
NSData*Arc<[u8]>
NSMutableData*Vec<u8>
NSString*Arc<str>
NSMutableString*String
NSValue*Arc<dyn Any>
NSNumber*Arc<enum { I8(i8), U8(u8), I16(i16), U16(u16), I32(i32), U32(u32), I64(i64), U64(u64), F32(f32), F64(f64), CLong(ffi::c_long), CULong(ffi::c_ulong) }>
NSError*Arc<dyn Error + Send + Sync>
NSException*Arc<dyn Error + Send + Sync>
NSRangeops::Range<usize>
NSComparisonResultcmp::Ordering
NSArray<T>*Arc<[T]>
NSMutableArray<T>*Vec<T>
NSDictionary<K, V>*Arc<HashMap<K, V>>
NSMutableDictionary<K, V>*HashMap<K, V>
NSEnumerator<T>*Box<dyn Iterator<T>>
NSCopying*Box<dyn Clone>

§Example

$ cargo add icrate --features=Foundation,Foundation_all
use icrate::Foundation::{ns_string, NSCopying, NSArray};

let string = ns_string!("world");
println!("hello {string}");

let array = NSArray::from_id_slice(&[string.copy()]);
println!("{array:?}");

Re-exports§

pub extern crate block2;
pub extern crate objc2;

Modules§

AccessibilityDeprecatedAccessibility
Bindings to the Accessibility framework
AdServicesDeprecatedAdServices
Bindings to the AdServices framework
AdSupportDeprecatedAdSupport
Bindings to the AdSupport framework
AppKitDeprecatedAppKit
Bindings to the AppKit framework
AuthenticationServicesDeprecatedAuthenticationServices
Bindings to the AuthenticationServices framework
AutomaticAssessmentConfigurationDeprecatedAutomaticAssessmentConfiguration
Bindings to the AutomaticAssessmentConfiguration framework
AutomatorDeprecatedAutomator
Bindings to the Automator framework
BackgroundAssetsDeprecatedBackgroundAssets
Bindings to the BackgroundAssets framework
BusinessChatDeprecatedBusinessChat
Bindings to the BusinessChat framework
CallKitDeprecatedCallKit
Bindings to the CallKit framework
ClassKitDeprecatedClassKit
Bindings to the ClassKit framework
CloudKitDeprecatedCloudKit
Bindings to the CloudKit framework
ContactsDeprecatedContacts
Bindings to the Contacts framework
CoreDataDeprecatedCoreData
Bindings to the CoreData framework
CoreLocationDeprecatedCoreLocation
Bindings to the CoreLocation framework
CoreWLANDeprecatedCoreWLAN
Bindings to the CoreWLAN framework
DataDetectionDeprecatedDataDetection
Bindings to the DataDetection framework
DeviceCheckDeprecatedDeviceCheck
Bindings to the DeviceCheck framework
EventKitDeprecatedEventKit
Bindings to the EventKit framework
ExceptionHandlingDeprecatedExceptionHandling
Bindings to the ExceptionHandling framework
ExtensionKitDeprecatedExtensionKit
Bindings to the ExtensionKit framework
ExternalAccessoryDeprecatedExternalAccessory
Bindings to the ExternalAccessory framework
FileProviderDeprecatedFileProvider
Bindings to the FileProvider framework
FileProviderUIDeprecatedFileProviderUI
Bindings to the FileProviderUI framework
FoundationDeprecatedFoundation
Bindings to the Foundation framework
GameControllerDeprecatedGameController
Bindings to the GameController framework
GameKitDeprecatedGameKit
Bindings to the GameKit framework
HealthKitDeprecatedHealthKit
Bindings to the HealthKit framework
IdentityLookupDeprecatedIdentityLookup
Bindings to the IdentityLookup framework
InputMethodKitDeprecatedInputMethodKit
Bindings to the InputMethodKit framework
LinkPresentationDeprecatedLinkPresentation
Bindings to the LinkPresentation framework
LocalAuthenticationDeprecatedLocalAuthentication
Bindings to the LocalAuthentication framework
LocalAuthenticationEmbeddedUIDeprecatedLocalAuthenticationEmbeddedUI
Bindings to the LocalAuthenticationEmbeddedUI framework
MailKitDeprecatedMailKit
Bindings to the MailKit framework
MapKitDeprecatedMapKit
Bindings to the MapKit framework
MediaPlayerDeprecatedMediaPlayer
Bindings to the MediaPlayer framework
MetalDeprecatedMetal
Bindings to the Metal framework
MetalFXDeprecatedMetalFX
Bindings to the MetalFX framework
MetalKitDeprecatedMetalKit
Bindings to the MetalKit framework
MetricKitDeprecatedMetricKit
Bindings to the MetricKit framework
OSAKitDeprecatedOSAKit
Bindings to the OSAKit framework
SoundAnalysisDeprecatedSoundAnalysis
Bindings to the SoundAnalysis framework
SpeechDeprecatedSpeech
Bindings to the Speech framework
StoreKitDeprecatedStoreKit
Bindings to the StoreKit framework
UniformTypeIdentifiersDeprecatedUniformTypeIdentifiers
Bindings to the UniformTypeIdentifiers framework
UserNotificationsDeprecatedUserNotifications
Bindings to the UserNotifications framework
WebKitDeprecatedWebKit
Bindings to the WebKit framework

Macros§

ns_stringDeprecatedFoundation_NSString
Deprecated alias of Foundation::ns_string.