1#[macro_use]
2extern crate objc;
3
4use objc::Encode;
5use objc::rc::StrongPtr;
6use objc::runtime::{Class, Object};
7
8fn main() {
9 let cls = class!(NSObject);
11 println!("NSObject size: {}", cls.instance_size());
12
13 println!("NSObject ivars:");
15 for ivar in cls.instance_variables().iter() {
16 println!("{}", ivar.name());
17 }
18
19 let obj = unsafe {
21 let obj: *mut Object = msg_send![cls, alloc];
22 let obj: *mut Object = msg_send![obj, init];
23 StrongPtr::new(obj)
24 };
25 println!("NSObject address: {:p}", obj);
26
27 let isa: *const Class = unsafe {
29 *(**obj).get_ivar("isa")
30 };
31 println!("NSObject isa: {:?}", isa);
32
33 let hash_sel = sel!(hash);
35 let hash_method = cls.instance_method(hash_sel).unwrap();
36 let hash_return = hash_method.return_type();
37 println!("-[NSObject hash] return type: {:?}", hash_return);
38 assert!(hash_return == usize::encode());
39
40 let hash: usize = unsafe {
42 msg_send![*obj, hash]
43 };
44 println!("NSObject hash: {}", hash);
45}