nspointerarray

NSPointerArray weird compaction

强颜欢笑 提交于 2019-12-06 19:01:11
问题 I have a weak NSPointerArray with some NSObject that has been released. Before calling compact what I see is: (lldb) po [currentArray count] 1 (lldb) po [currentArray pointerAtIndex:0] <nil> (lldb) po [currentArray allObjects] <__NSArrayM 0x16f04f00>( ) That makes sense, but what is really weird is that when I call compact on that array I see the same values! Count still returns 1 and pointerAtIndex:0 is nil . Why the nil hasn't been removed? EDIT Here's the full code (yeah it's XCTesting

NSPointerArray weird compaction

て烟熏妆下的殇ゞ 提交于 2019-12-05 00:37:26
I have a weak NSPointerArray with some NSObject that has been released. Before calling compact what I see is: (lldb) po [currentArray count] 1 (lldb) po [currentArray pointerAtIndex:0] <nil> (lldb) po [currentArray allObjects] <__NSArrayM 0x16f04f00>( ) That makes sense, but what is really weird is that when I call compact on that array I see the same values! Count still returns 1 and pointerAtIndex:0 is nil . Why the nil hasn't been removed? EDIT Here's the full code (yeah it's XCTesting framework): - (void)testCompaction { __weak id testingPointer = nil; NSPointerArray *weakArray =

How do I declare an array of weak references in Swift?

青春壹個敷衍的年華 提交于 2019-11-26 21:26:17
I'd like to store an array of weak references in Swift. The array itself should not be a weak reference - its elements should be. I think Cocoa NSPointerArray offers a non-typesafe version of this. Create a generic wrapper as: class Weak<T: AnyObject> { weak var value : T? init (value: T) { self.value = value } } Add instances of this class to your array. class Stuff {} var weakly : [Weak<Stuff>] = [Weak(value: Stuff()), Weak(value: Stuff())] When defining Weak you can use either struct or class . Also, to help with reaping array contents, you could do something along the lines of: extension

How do I declare an array of weak references in Swift?

空扰寡人 提交于 2019-11-26 06:58:50
问题 I\'d like to store an array of weak references in Swift. The array itself should not be a weak reference - its elements should be. I think Cocoa NSPointerArray offers a non-typesafe version of this. 回答1: Create a generic wrapper as: class Weak<T: AnyObject> { weak var value : T? init (value: T) { self.value = value } } Add instances of this class to your array. class Stuff {} var weakly : [Weak<Stuff>] = [Weak(value: Stuff()), Weak(value: Stuff())] When defining Weak you can use either struct