@@ -96,45 +96,81 @@ - (void)demoHash {
96
96
NSIndexPath *five = [NSIndexPath indexPathForRow: 1 inSection: 1 ];
97
97
/*
98
98
(lldb) p one
99
- (NSIndexPath *) $7 = 0xc000000000000016
99
+ (NSIndexPath *) $1 = 0xc000000000000016
100
100
(lldb) p two
101
- (NSIndexPath *) $8 = 0xc000000000000016
101
+ (NSIndexPath *) $2 = 0xc000000000000016
102
102
(lldb) p three
103
- (NSIndexPath *) $9 = 0xc000000000200016
103
+ (NSIndexPath *) $3 = 0xc000000000200016
104
104
(lldb) p four
105
- (NSIndexPath *) $10 = 0xc000000000200016
105
+ (NSIndexPath *) $4 = 0xc000000000200016
106
106
(lldb) p five
107
- (NSIndexPath *) $11 = 0xc000000000200116
107
+ (NSIndexPath *) $5 = 0xc000000000200116
108
+ (lldb) p one==two
109
+ (bool) $6 = true
108
110
*/
109
111
110
112
NSString *s1 = [[NSString alloc ] initWithFormat: @" s" ];
111
113
NSString *s2 = [[NSString alloc ] initWithFormat: @" s" ];
114
+ // 因此仅不可变字符串是同一内存地址,其他都是不同地址。
115
+
116
+ NSMutableString *ms1 = [[NSMutableString alloc ] initWithString: @" ms" ];
117
+ NSMutableString *ms2 = [[NSMutableString alloc ] initWithString: @" ms" ];
112
118
/*
113
- (lldb) p s1
114
- (NSTaggedPointerString *) $1 = 0xa000000000000731 @"s"
115
- (lldb) p s2
116
- (NSTaggedPointerString *) $2 = 0xa000000000000731 @"s"
119
+ (lldb) p s1
120
+ (NSTaggedPointerString *) $11 = 0xa000000000000731 @"s"
121
+ (lldb) p s2
122
+ (NSTaggedPointerString *) $12 = 0xa000000000000731 @"s"
123
+ (lldb) p ms1
124
+ (__NSCFString *) $13 = 0x00007fede2839e30 @"ms"
125
+ (lldb) p ms2
126
+ (__NSCFString *) $14 = 0x00007fede2805bb0 @"ms"
127
+ (lldb) p [ms1 isEqual:ms2]
128
+ (BOOL) $15 = YES
129
+ (lldb) p [ms1 isEqualToString:ms2]
130
+ (BOOL) $16 = YES
117
131
*/
118
132
119
-
120
133
NSArray *a1 = [[NSArray alloc ] initWithObjects: @" 1" , @" 2" , nil ];
121
134
NSArray *a2 = [[NSArray alloc ] initWithObjects: @" 1" , @" 2" , nil ];
135
+
136
+ NSMutableArray *ma1 = [[NSMutableArray alloc ] initWithArray: @[@" 1" , @" 2" ]];
137
+ NSMutableArray *ma2 = [[NSMutableArray alloc ] initWithArray: @[@" 1" , @" 2" ]];
122
138
/*
123
139
(lldb) p a1
124
- (__NSArrayI *) $3 = 0x00007fa01bd4b5a0 @"2 objects"
140
+ (__NSArrayI *) $21 = 0x00007fede2830cb0 @"2 objects"
125
141
(lldb) p a2
126
- (__NSArrayI *) $4 = 0x00007fa01bd4a5e0 @"2 objects"
142
+ (__NSArrayI *) $22 = 0x00007fede2826ee0 @"2 objects"
143
+ (lldb) p ma1
144
+ (__NSArrayM *) $23 = 0x00007fede282e780 @"2 objects"
145
+ (lldb) p ma2
146
+ (__NSArrayM *) $24 = 0x00007fede2848100 @"2 objects"
147
+ (lldb) p [a1 isEqual:a2]
148
+ (BOOL) $25 = YES
149
+ (lldb) p [ma1 isEqual:ma2]
150
+ (BOOL) $26 = YES
127
151
*/
128
152
129
153
NSDictionary *d1 = [[NSDictionary alloc ] initWithObjectsAndKeys: @" value" , @" key" , nil ];
130
154
NSDictionary *d2 = [[NSDictionary alloc ] initWithObjectsAndKeys: @" value" , @" key" , nil ];
155
+
156
+ NSMutableDictionary *md1 = [[NSMutableDictionary alloc ] initWithObjectsAndKeys: @" value" , @" key" , nil ];
157
+ NSMutableDictionary *md2 = [[NSMutableDictionary alloc ] initWithObjectsAndKeys: @" value" , @" key" , nil ];
131
158
/*
132
159
(lldb) p d1
133
- (__NSDictionaryI *) $5 = 0x00007fa01bd45800 1 key/value pair
160
+ (__NSDictionaryI *) $31 = 0x00007fede2847c00 1 key/value pair
134
161
(lldb) p d2
135
- (__NSDictionaryI *) $6 = 0x00007fa01bd4da00 1 key/value pair
162
+ (__NSDictionaryI *) $32 = 0x00007fede2847d00 1 key/value pair
163
+ (lldb) p md1
164
+ (__NSDictionaryM *) $33 = 0x00007fede2858480 1 key/value pair
165
+ (lldb) p md2
166
+ (__NSDictionaryM *) $34 = 0x00007fede28584b0 1 key/value pair
167
+ (lldb) p [d1 isEqual:d2]
168
+ (BOOL) $35 = YES
169
+ (lldb) p [md1 isEqual:md2]
170
+ (BOOL) $36 = YES
136
171
*/
137
172
173
+
138
174
MyClass *cls1 = [[MyClass alloc ] init ];
139
175
cls1.name = @" cls" ;
140
176
@@ -152,21 +188,35 @@ - (void)demoHash {
152
188
/*
153
189
NSObject的hash值暂时不清楚如何来的。
154
190
(lldb) p s1.hash
155
- (NSUInteger) $15 = 1116
191
+ (NSUInteger) $81 = 1116
156
192
(lldb) p s2.hash
157
- (NSUInteger) $16 = 1116
193
+ (NSUInteger) $82 = 1116
194
+ (lldb) p ms1.hash
195
+ (NSUInteger) $83 = 801130
196
+ (lldb) p ms2.hash
197
+ (NSUInteger) $84 = 801130
158
198
(lldb) p a1.hash
159
- (NSUInteger) $17 = 2
199
+ (NSUInteger) $85 = 2
160
200
(lldb) p a2.hash
161
- (NSUInteger) $18 = 2
201
+ (NSUInteger) $86 = 2
202
+ (lldb) p ma1.hash
203
+ (NSUInteger) $87 = 2
204
+ (lldb) p ma2.hash
205
+ (NSUInteger) $88 = 2
162
206
(lldb) p d1.hash
163
- (NSUInteger) $19 = 1
207
+ (NSUInteger) $89 = 1
164
208
(lldb) p d2.hash
165
- (NSUInteger) $20 = 1
209
+ (NSUInteger) $90 = 1
210
+ (lldb) p md1.hash
211
+ (NSUInteger) $91 = 1
212
+ (lldb) p md2.hash
213
+ (NSUInteger) $92 = 1
214
+
215
+
166
216
(lldb) p cls1.hash
167
- (NSUInteger) $21 = 140325638356064
217
+ (NSUInteger) $93 = 140659655418304
168
218
(lldb) p cls2.hash
169
- (NSUInteger) $22 = 140325638419984
219
+ (NSUInteger) $94 = 140659655340752
170
220
*/
171
221
}
172
222
0 commit comments