1
1
data ! {
2
- class NSArray {
2
+ // SAFETY: `new` or `initWithObjects:` may choose to deduplicate arrays,
3
+ // and returning mutable references to those would be unsound - hence
4
+ // `NSArray` cannot be mutable.
5
+ class NSArray : ImmutableWithMutableSubclass <Foundation :: NSMutableArray > {
3
6
unsafe -count;
4
7
}
5
8
6
- class NSMutableArray : Owned {
7
- unsafe mut -removeAllObjects;
8
- mut -addObject;
9
- mut -insertObject_atIndex;
10
- mut -replaceObjectAtIndex_withObject;
11
- mut -removeObjectAtIndex;
12
- mut -removeLastObject;
13
- mut -sortUsingFunction_context;
9
+ class NSMutableArray : MutableWithImmutableSuperclass <Foundation :: NSArray > {
10
+ unsafe -removeAllObjects;
14
11
}
15
12
16
- class NSString {
13
+ class NSString : ImmutableWithMutableSubclass < Foundation :: NSMutableString > {
17
14
unsafe -init;
18
15
unsafe -compare;
19
16
unsafe -hasPrefix;
@@ -30,59 +27,66 @@ data! {
30
27
unsafe +stringWithString;
31
28
}
32
29
33
- class NSMutableString : Owned {
30
+ class NSMutableString : MutableWithImmutableSuperclass < Foundation :: NSString > {
34
31
unsafe -initWithCapacity;
35
32
unsafe +stringWithCapacity;
36
33
unsafe -initWithString;
37
34
unsafe +stringWithString;
38
- unsafe mut -appendString;
39
- unsafe mut -setString;
35
+ unsafe -appendString;
36
+ unsafe -setString;
40
37
}
41
38
42
- class NSAttributedString {
39
+ // Allowed to be just `Immutable` since we've removed the `NSCopying` and
40
+ // `NSMutableCopying` impls from these for now (they'd return the wrong
41
+ // type).
42
+ class NSSimpleCString : Immutable { }
43
+ class NSConstantString : Immutable { }
44
+
45
+ class NSAttributedString : ImmutableWithMutableSubclass <Foundation :: NSMutableAttributedString > {
43
46
unsafe -initWithString;
44
47
unsafe -initWithAttributedString;
45
48
unsafe -string;
46
49
unsafe -length;
47
50
}
48
51
49
- class NSMutableAttributedString : Owned {
52
+ class NSMutableAttributedString : MutableWithImmutableSuperclass < Foundation :: NSAttributedString > {
50
53
unsafe -initWithString;
51
54
unsafe -initWithAttributedString;
52
- unsafe mut -setAttributedString;
55
+ unsafe -setAttributedString;
53
56
}
54
57
55
58
class NSBundle {
56
59
unsafe +mainBundle;
57
60
unsafe -infoDictionary;
58
61
}
59
62
60
- class NSData {
63
+ class NSData : ImmutableWithMutableSubclass < Foundation :: NSMutableData > {
61
64
unsafe -initWithData;
62
65
unsafe +dataWithData;
63
66
unsafe -length;
64
67
unsafe -bytes;
65
68
}
66
69
67
- class NSMutableData : Owned {
70
+ class NSMutableData : MutableWithImmutableSuperclass < Foundation :: NSData > {
68
71
unsafe +dataWithData;
69
72
unsafe -initWithCapacity;
70
73
unsafe +dataWithCapacity;
71
- unsafe mut -setLength;
72
- unsafe mut -mutableBytes;
74
+ unsafe -setLength;
75
+ unsafe -mutableBytes;
73
76
}
74
77
75
- class NSDictionary {
78
+ // Allowed to be just `Mutable` since we've removed the `NSCopying` and
79
+ // `NSMutableCopying` impls from this for now (since they'd return the
80
+ // wrong type).
81
+ class NSPurgeableData : Mutable { }
82
+
83
+ class NSDictionary : ImmutableWithMutableSubclass <Foundation :: NSMutableDictionary > {
76
84
unsafe -count;
77
- unsafe -objectForKey;
78
- unsafe -allKeys;
79
- unsafe -allValues;
80
85
}
81
86
82
- class NSMutableDictionary : Owned {
83
- unsafe mut -setDictionary;
84
- unsafe mut -removeObjectForKey;
85
- unsafe mut -removeAllObjects;
87
+ class NSMutableDictionary : MutableWithImmutableSuperclass <Foundation :: NSDictionary > {
88
+ unsafe -removeObjectForKey;
89
+ unsafe -removeAllObjects;
86
90
}
87
91
88
92
class NSError {
@@ -130,20 +134,22 @@ data! {
130
134
unsafe -operatingSystemVersion;
131
135
}
132
136
133
- class NSSet {
137
+ class NSSet : ImmutableWithMutableSubclass < Foundation :: NSMutableSet > {
134
138
unsafe -count;
135
139
}
136
140
137
- class NSMutableSet : Owned {
138
- unsafe mut -removeAllObjects;
139
- mut -addObject;
141
+ class NSMutableSet : MutableWithImmutableSuperclass <Foundation :: NSSet > {
142
+ unsafe -removeAllObjects;
140
143
}
141
144
142
- class NSMutableCharacterSet : Owned { }
145
+ class NSCharacterSet : ImmutableWithMutableSubclass <Foundation :: NSMutableCharacterSet > { }
146
+ class NSMutableCharacterSet : MutableWithImmutableSuperclass <Foundation :: NSCharacterSet > { }
143
147
144
- class NSMutableOrderedSet : Owned { }
148
+ class NSOrderedSet : ImmutableWithMutableSubclass <Foundation :: NSMutableOrderedSet > { }
149
+ class NSMutableOrderedSet : MutableWithImmutableSuperclass <Foundation :: NSOrderedSet > { }
145
150
146
- class NSMutableIndexSet : Owned { }
151
+ class NSIndexSet : ImmutableWithMutableSubclass <Foundation :: NSMutableIndexSet > { }
152
+ class NSMutableIndexSet : MutableWithImmutableSuperclass <Foundation :: NSIndexSet > { }
147
153
148
154
class NSNumber {
149
155
unsafe -initWithChar;
@@ -196,5 +202,6 @@ data! {
196
202
unsafe -stringValue;
197
203
}
198
204
199
- class NSMutableURLRequest : Owned { }
205
+ class NSURLRequest : ImmutableWithMutableSubclass <Foundation :: NSMutableURLRequest > { }
206
+ class NSMutableURLRequest : MutableWithImmutableSuperclass <Foundation :: NSURLRequest > { }
200
207
}
0 commit comments