| __ns_macro_helpers |
|
|
| array.rs |
Utilities for the `NSArray` and `NSMutableArray` classes. |
16771 |
| attributed_string.rs |
|
1633 |
| bundle.rs |
|
489 |
| comparison_result.rs |
|
1526 |
| copying.rs |
|
8610 |
| data.rs |
|
10580 |
| decimal.rs |
|
888 |
| dictionary.rs |
Utilities for the `NSDictionary` and `NSMutableDictionary` classes. |
19036 |
| enumerator.rs |
Utilities for the `NSEnumerator` class. |
2720 |
| error.rs |
|
2658 |
| exception.rs |
|
3825 |
| fast_enumeration_state.rs |
|
776 |
| generated |
|
|
| geometry.rs |
|
4500 |
| iter.rs |
|
23854 |
| lib.rs |
# Bindings to the `Foundation` framework
See [Apple's docs][apple-doc] and [the general docs on framework crates][framework-crates] for more information.
[apple-doc]: https://developer.apple.com/documentation/foundation/
[framework-crates]: https://docs.rs/objc2/latest/objc2/topics/about_generated/index.html
This is the [`std`] equivalent for Objective-C, containing essential data
types, collections, and operating-system services.
## 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*` | `Rc<[u8]>` |
| `NSMutableData*` | `Rc<Cell<Vec<u8>>>` |
| `NSString*` | `Rc<str>` |
| `NSMutableString*` | `Rc<Cell<String>>` |
| `NSValue*` | `Rc<dyn Any>` |
| `NSNumber*` | `Arc<enum { I8(i8), U8(u8), I16(i16), ... }>` |
| `NSError*` | `Arc<dyn Error + Send + Sync>` |
| `NSException*` | `Arc<dyn Error + Send + Sync>` |
| `NSRange` | `ops::Range<usize>` |
| `NSComparisonResult` | `cmp::Ordering` |
| `NSEnumerator<T>*` | `Rc<dyn Iterator<Item = Retained<T>>>` |
| `NSCopying*` | `Rc<dyn Clone>` |
| `NSArray<T>*` | `Rc<[Retained<T>]>` |
| `NSMutableArray<T>*` | `Rc<Cell<Vec<Retained<T>>>>` |
| `NSDictionary<K, V>*` | `Rc<HashMap<Retained<K>, Retained<V>>>` |
| `NSMutableDictionary<K, V>*` | `Rc<Cell<HashMap<Retained<K>, Retained<V>>>>` |
Note, in particular, that all "Mutable" variants use interior mutability,
and that some things are thread-safe (`Arc`), while others are not (`Rc`).
## Examples
Basic usage of a few Foundation types.
```console
$ cargo add objc2-foundation
```
|
8267 |
| macros |
|
|
| ns_consumed.rs |
|
188 |
| number.rs |
Note that due to limitations in Objective-C type encodings, it is not
possible to distinguish between an `NSNumber` created from [`bool`],
and one created from an [`i8`]/[`u8`]. You should use the getter
methods that fit your use-case instead!
This does not implement [`Eq`] nor [`Ord`], since it may contain a
floating point value. Beware that the implementation of [`PartialEq`]
and [`PartialOrd`] does not properly handle NaNs either. Compare
[`NSNumber::encoding`] with [`Encoding::Float`] or
[`Encoding::Double`], and use [`NSNumber::as_f32`] or
[`NSNumber::as_f64`] to get the desired floating point value directly.
TODO: Once we have better CoreFoundation support, use that to create
efficient static numbers. See:
<https://github.com/nvzqz/fruity/blob/811d7787495eaaee6bc39d372004e5d96ef9f49b/src/foundation/ns_number.rs#L328-L401>
(Same goes for `NSNull`). |
8820 |
| process_info.rs |
|
465 |
| range.rs |
|
4857 |
| set.rs |
Utilities for the `NSSet` and `NSMutableSet` classes. |
11279 |
| string.rs |
|
7932 |
| tests |
|
|
| thread.rs |
|
843 |
| to_owned.rs |
|
2684 |
| url.rs |
|
9544 |
| user_defaults.rs |
|
238 |
| util.rs |
|
1773 |
| uuid.rs |
|
3747 |
| value.rs |
|
5733 |