objc_foundation

Trait INSObject

Source
pub trait INSObject:
    Any
    + Sized
    + Message {
    // Required method
    fn class() -> &'static Class;

    // Provided methods
    fn hash_code(&self) -> usize { ... }
    fn is_equal<T>(&self, other: &T) -> bool
       where T: INSObject { ... }
    fn description(&self) -> ShareId<NSString> { ... }
    fn is_kind_of(&self, cls: &Class) -> bool { ... }
    fn new() -> Id<Self> { ... }
}

Required Methods§

Source

fn class() -> &'static Class

Provided Methods§

Source

fn hash_code(&self) -> usize

Source

fn is_equal<T>(&self, other: &T) -> bool
where T: INSObject,

Source

fn description(&self) -> ShareId<NSString>

Source

fn is_kind_of(&self, cls: &Class) -> bool

Source

fn new() -> Id<Self>

Examples found in repository?
examples/custom_class.rs (line 65)
64
65
66
67
68
69
70
71
72
73
74
75
76
77
fn main() {
    let mut obj = MYObject::new();

    obj.set_number(7);
    println!("Number: {}", unsafe {
        let number: u32 = msg_send![obj, number];
        number
    });

    unsafe {
        let _: () = msg_send![obj, setNumber:12u32];
    }
    println!("Number: {}", obj.number());
}
More examples
Hide additional examples
examples/example.rs (line 8)
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
fn main() {
    // Create and compare NSObjects
    let obj = NSObject::new();
    println!("{:?} == {:?}? {:?}", obj, obj, obj == obj);

    let obj2 = NSObject::new();
    println!("{:?} == {:?}? {:?}", obj, obj2, obj == obj2);

    // Create an NSArray from a Vec
    let objs = vec![obj, obj2];
    let array = NSArray::from_vec(objs);
    for obj in array.object_enumerator() {
        println!("{:?}", obj);
    }
    println!("{}", array.count());

    // Turn the NSArray back into a Vec
    let mut objs = NSArray::into_vec(array);
    let obj = objs.pop().unwrap();

    // Create an NSString from a str slice
    let string = NSString::from_str("Hello, world!");
    println!("{}", string.as_str());
    let string2 = string.copy();
    println!("{}", string2.as_str());

    // Create a dictionary mapping strings to objects
    let keys = &[&*string];
    let vals = vec![obj];
    let dict = NSDictionary::from_keys_and_objects(keys, vals);
    println!("{:?}", dict.object_for(&string));
    println!("{}", dict.count());
}

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§