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_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§
Modules§
- Accessibility
Deprecated Accessibility
- Bindings to the
Accessibility
framework - AdServices
Deprecated AdServices
- Bindings to the
AdServices
framework - AdSupport
Deprecated AdSupport
- Bindings to the
AdSupport
framework - AppKit
Deprecated AppKit
- Bindings to the
AppKit
framework - Authentication
Services Deprecated AuthenticationServices
- Bindings to the
AuthenticationServices
framework - Automatic
Assessment Configuration Deprecated AutomaticAssessmentConfiguration
- Bindings to the
AutomaticAssessmentConfiguration
framework - Automator
Deprecated Automator
- Bindings to the
Automator
framework - Background
Assets Deprecated BackgroundAssets
- Bindings to the
BackgroundAssets
framework - Business
Chat Deprecated BusinessChat
- Bindings to the
BusinessChat
framework - CallKit
Deprecated CallKit
- Bindings to the
CallKit
framework - Class
Kit Deprecated ClassKit
- Bindings to the
ClassKit
framework - Cloud
Kit Deprecated CloudKit
- Bindings to the
CloudKit
framework - Contacts
Deprecated Contacts
- Bindings to the
Contacts
framework - Core
Data Deprecated CoreData
- Bindings to the
CoreData
framework - Core
Location Deprecated CoreLocation
- Bindings to the
CoreLocation
framework - CoreWLAN
Deprecated CoreWLAN
- Bindings to the
CoreWLAN
framework - Data
Detection Deprecated DataDetection
- Bindings to the
DataDetection
framework - Device
Check Deprecated DeviceCheck
- Bindings to the
DeviceCheck
framework - Event
Kit Deprecated EventKit
- Bindings to the
EventKit
framework - Exception
Handling Deprecated ExceptionHandling
- Bindings to the
ExceptionHandling
framework - Extension
Kit Deprecated ExtensionKit
- Bindings to the
ExtensionKit
framework - External
Accessory Deprecated ExternalAccessory
- Bindings to the
ExternalAccessory
framework - File
Provider Deprecated FileProvider
- Bindings to the
FileProvider
framework - File
ProviderUI Deprecated FileProviderUI
- Bindings to the
FileProviderUI
framework - Foundation
Deprecated Foundation
- Bindings to the
Foundation
framework - Game
Controller Deprecated GameController
- Bindings to the
GameController
framework - GameKit
Deprecated GameKit
- Bindings to the
GameKit
framework - Health
Kit Deprecated HealthKit
- Bindings to the
HealthKit
framework - Identity
Lookup Deprecated IdentityLookup
- Bindings to the
IdentityLookup
framework - Input
Method Kit Deprecated InputMethodKit
- Bindings to the
InputMethodKit
framework - Link
Presentation Deprecated LinkPresentation
- Bindings to the
LinkPresentation
framework - Local
Authentication Deprecated LocalAuthentication
- Bindings to the
LocalAuthentication
framework - Local
Authentication EmbeddedUI Deprecated LocalAuthenticationEmbeddedUI
- Bindings to the
LocalAuthenticationEmbeddedUI
framework - MailKit
Deprecated MailKit
- Bindings to the
MailKit
framework - MapKit
Deprecated MapKit
- Bindings to the
MapKit
framework - Media
Player Deprecated MediaPlayer
- Bindings to the
MediaPlayer
framework - Metal
Deprecated Metal
- Bindings to the
Metal
framework - MetalFX
Deprecated MetalFX
- Bindings to the
MetalFX
framework - Metal
Kit Deprecated MetalKit
- Bindings to the
MetalKit
framework - Metric
Kit Deprecated MetricKit
- Bindings to the
MetricKit
framework - OSAKit
Deprecated OSAKit
- Bindings to the
OSAKit
framework - Sound
Analysis Deprecated SoundAnalysis
- Bindings to the
SoundAnalysis
framework - Speech
Deprecated Speech
- Bindings to the
Speech
framework - Store
Kit Deprecated StoreKit
- Bindings to the
StoreKit
framework - Uniform
Type Identifiers Deprecated UniformTypeIdentifiers
- Bindings to the
UniformTypeIdentifiers
framework - User
Notifications Deprecated UserNotifications
- Bindings to the
UserNotifications
framework - WebKit
Deprecated WebKit
- Bindings to the
WebKit
framework
Macros§
- ns_
string Deprecated Foundation_NSString
- Deprecated alias of
Foundation::ns_string
.