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> |
NSRange | ops::Range<usize> |
NSComparisonResult | cmp::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_alluse 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§
Modules§
- Accessibility
Deprecated Accessibility - Bindings to the
Accessibilityframework - AdServices
Deprecated AdServices - Bindings to the
AdServicesframework - AdSupport
Deprecated AdSupport - Bindings to the
AdSupportframework - AppKit
Deprecated AppKit - Bindings to the
AppKitframework - Authentication
Services Deprecated AuthenticationServices - Bindings to the
AuthenticationServicesframework - Automatic
Assessment Configuration Deprecated AutomaticAssessmentConfiguration - Bindings to the
AutomaticAssessmentConfigurationframework - Automator
Deprecated Automator - Bindings to the
Automatorframework - Background
Assets Deprecated BackgroundAssets - Bindings to the
BackgroundAssetsframework - Business
Chat Deprecated BusinessChat - Bindings to the
BusinessChatframework - CallKit
Deprecated CallKit - Bindings to the
CallKitframework - Class
Kit Deprecated ClassKit - Bindings to the
ClassKitframework - Cloud
Kit Deprecated CloudKit - Bindings to the
CloudKitframework - Contacts
Deprecated Contacts - Bindings to the
Contactsframework - Core
Data Deprecated CoreData - Bindings to the
CoreDataframework - Core
Location Deprecated CoreLocation - Bindings to the
CoreLocationframework - CoreWLAN
Deprecated CoreWLAN - Bindings to the
CoreWLANframework - Data
Detection Deprecated DataDetection - Bindings to the
DataDetectionframework - Device
Check Deprecated DeviceCheck - Bindings to the
DeviceCheckframework - Event
Kit Deprecated EventKit - Bindings to the
EventKitframework - Exception
Handling Deprecated ExceptionHandling - Bindings to the
ExceptionHandlingframework - Extension
Kit Deprecated ExtensionKit - Bindings to the
ExtensionKitframework - External
Accessory Deprecated ExternalAccessory - Bindings to the
ExternalAccessoryframework - File
Provider Deprecated FileProvider - Bindings to the
FileProviderframework - File
ProviderUI Deprecated FileProviderUI - Bindings to the
FileProviderUIframework - Foundation
Deprecated Foundation - Bindings to the
Foundationframework - Game
Controller Deprecated GameController - Bindings to the
GameControllerframework - GameKit
Deprecated GameKit - Bindings to the
GameKitframework - Health
Kit Deprecated HealthKit - Bindings to the
HealthKitframework - Identity
Lookup Deprecated IdentityLookup - Bindings to the
IdentityLookupframework - Input
Method Kit Deprecated InputMethodKit - Bindings to the
InputMethodKitframework - Link
Presentation Deprecated LinkPresentation - Bindings to the
LinkPresentationframework - Local
Authentication Deprecated LocalAuthentication - Bindings to the
LocalAuthenticationframework - Local
Authentication EmbeddedUI Deprecated LocalAuthenticationEmbeddedUI - Bindings to the
LocalAuthenticationEmbeddedUIframework - MailKit
Deprecated MailKit - Bindings to the
MailKitframework - MapKit
Deprecated MapKit - Bindings to the
MapKitframework - Media
Player Deprecated MediaPlayer - Bindings to the
MediaPlayerframework - Metal
Deprecated Metal - Bindings to the
Metalframework - MetalFX
Deprecated MetalFX - Bindings to the
MetalFXframework - Metal
Kit Deprecated MetalKit - Bindings to the
MetalKitframework - Metric
Kit Deprecated MetricKit - Bindings to the
MetricKitframework - OSAKit
Deprecated OSAKit - Bindings to the
OSAKitframework - Sound
Analysis Deprecated SoundAnalysis - Bindings to the
SoundAnalysisframework - Speech
Deprecated Speech - Bindings to the
Speechframework - Store
Kit Deprecated StoreKit - Bindings to the
StoreKitframework - Uniform
Type Identifiers Deprecated UniformTypeIdentifiers - Bindings to the
UniformTypeIdentifiersframework - User
Notifications Deprecated UserNotifications - Bindings to the
UserNotificationsframework - WebKit
Deprecated WebKit - Bindings to the
WebKitframework
Macros§
- ns_
string Deprecated Foundation_NSString - Deprecated alias of
Foundation::ns_string.