작동 방법 : "키 및/또는 값이 선택적으로 개최 다음 documentation에 작성된NSMapTable 내가 NSMapTable이 그래서 내가 놀이터에서 다음 코드를 시도하고 어떻게 작동하는지 알아 내려고 노력하고있어
class Person {
var name: String
init(name: String) {
self.name = name
print("\(name) is being initialized")
}
deinit {
print("\(name) is being deinitialized")
}
}
var hobyePerson : NSMapTable? = NSMapTable<Person, NSMutableString>
(keyOptions: .weakMemory, valueOptions: .weakMemory)
var rob : Person? = Person(name: "Rob Appleseed") // print : Rob Appleseed is being initialized
hobyePerson?.setObject("golf", forKey: rob)
hobyePerson?.count // return : 1
rob = nil // print : Rob Appleseed is being deinitialized
hobyePerson?.count // return : 1 (WHY ???!!!!)
을 개체 중 하나가 재생 될 때 항목이 제거되도록 "약하게"
왜 내가 rob을 할당 해제 할 때 키 - 값 쌍에 대한 약한 참조를 갖도록 객체를 초기화하더라도 hobyePerson에 여전히 요소가 있습니까?
이 http://cocoamine.net/blog/2013/12/13/nsmaptable-and-zeroing-weak-references/ 답변에 대한 –