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
use std::collections::HashMap;
use std::ops::{Deref, DerefMut};
use objc::runtime::Object;
use objc::{class, msg_send, sel, sel_impl};
use objc_id::Id;
use crate::foundation::{id, NSString};
#[derive(Debug)]
pub struct NSMutableDictionary(pub Id<Object>);
impl Default for NSMutableDictionary {
fn default() -> Self {
NSMutableDictionary::new()
}
}
impl NSMutableDictionary {
pub fn new() -> Self {
NSMutableDictionary(unsafe { Id::from_ptr(msg_send![class!(NSMutableDictionary), new]) })
}
pub fn insert(&mut self, key: NSString, object: id) {
unsafe {
let _: () = msg_send![&*self.0, setObject:object forKey:&*key];
}
}
pub fn into_inner(mut self) -> id {
&mut *self.0
}
}
impl Deref for NSMutableDictionary {
type Target = Object;
fn deref(&self) -> &Object {
&*self.0
}
}
impl DerefMut for NSMutableDictionary {
fn deref_mut(&mut self) -> &mut Object {
&mut *self.0
}
}