1
2
3
4
5
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
/*!
Objective-C Runtime bindings and wrapper for Rust.
# Messaging objects
Objective-C objects can be messaged using the [`msg_send!`](macro.msg_send!.html) macro:
```
# #[macro_use] extern crate objc;
# use objc::runtime::{BOOL, Class, Object};
# fn main() {
# unsafe {
let cls = Class::get("NSObject").unwrap();
let obj: *mut Object = msg_send![cls, new];
let hash: usize = msg_send![obj, hash];
let is_kind: BOOL = msg_send![obj, isKindOfClass:cls];
// Even void methods must have their return type annotated
let _: () = msg_send![obj, release];
# }
# }
```
# Reference counting
Objective-C objects are reference counted; to ensure that they are retained and
released at the proper times, we can use the [`Id`](struct.Id.html) struct.
To enforce aliasing rules, an `Id` can be either owned or shared; if it is
owned, meaning the `Id` is the only reference to the object, it can be mutably
dereferenced. An owned `Id` can be downgraded to a [`ShareId`](type.ShareId.html)
which can be cloned to allow multiple references.
Weak references may be created using the [`WeakId`](struct.WeakId.html) struct.
```
# #[macro_use] extern crate objc;
# use objc::runtime::{BOOL, Class, Object};
# use objc::{Id, WeakId};
# fn main() {
let cls = Class::get("NSObject").unwrap();
let obj: Id<Object> = unsafe {
Id::from_retained_ptr(msg_send![cls, new])
};
// obj will be released when it goes out of scope
// share the object so we can clone it
let obj = obj.share();
let another_ref = obj.clone();
// dropping our other reference will decrement the retain count
drop(another_ref);
let weak = WeakId::new(&obj);
assert!(weak.load().is_some());
// After the object is deallocated, our weak pointer returns none
drop(obj);
assert!(weak.load().is_none());
# }
```
# Calling and creating Blocks
Objective-C blocks can be called and created using the functionality of the
[`block`](block/index.html) module.
# Declaring classes
Objective-C classes can even be declared from Rust using the functionality of
the [`declare`](declare/index.html) module.
*/
extern crate libc;
extern crate malloc_buf;
extern crate objc_test_utils;
pub use ;
pub use ;
pub use ;
pub use WeakId;