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§
Provided Methods§
fn hash_code(&self) -> usize
fn is_equal<T>(&self, other: &T) -> boolwhere
T: INSObject,
fn description(&self) -> ShareId<NSString>
fn is_kind_of(&self, cls: &Class) -> bool
Sourcefn new() -> Id<Self>
fn new() -> Id<Self>
Examples found in repository?
examples/custom_class.rs (line 65)
64fn main() {
65 let mut obj = MYObject::new();
66
67 obj.set_number(7);
68 println!("Number: {}", unsafe {
69 let number: u32 = msg_send![obj, number];
70 number
71 });
72
73 unsafe {
74 let _: () = msg_send![obj, setNumber:12u32];
75 }
76 println!("Number: {}", obj.number());
77}
More examples
examples/example.rs (line 8)
6fn main() {
7 // Create and compare NSObjects
8 let obj = NSObject::new();
9 println!("{:?} == {:?}? {:?}", obj, obj, obj == obj);
10
11 let obj2 = NSObject::new();
12 println!("{:?} == {:?}? {:?}", obj, obj2, obj == obj2);
13
14 // Create an NSArray from a Vec
15 let objs = vec![obj, obj2];
16 let array = NSArray::from_vec(objs);
17 for obj in array.object_enumerator() {
18 println!("{:?}", obj);
19 }
20 println!("{}", array.count());
21
22 // Turn the NSArray back into a Vec
23 let mut objs = NSArray::into_vec(array);
24 let obj = objs.pop().unwrap();
25
26 // Create an NSString from a str slice
27 let string = NSString::from_str("Hello, world!");
28 println!("{}", string.as_str());
29 let string2 = string.copy();
30 println!("{}", string2.as_str());
31
32 // Create a dictionary mapping strings to objects
33 let keys = &[&*string];
34 let vals = vec![obj];
35 let dict = NSDictionary::from_keys_and_objects(keys, vals);
36 println!("{:?}", dict.object_for(&string));
37 println!("{}", dict.count());
38}
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.