[swift-users] access violation when weak variable
Ray Fix
rayfix at gmail.com
Sat Jul 9 09:18:11 CDT 2016
Hi!
When I make a variable weak in Xcode 8 (both beta 1 and beta 2) I get a access violation. I think this is a bug, but want to make sure I am not missing something.
Best regards,
Ray
//: Playground - noun: a place where people can play
import UIKit
class Person: CustomStringConvertible {
var name: String
weak var parent: Person? /// If I remove weak, no crash in Xcode 8 beta 2, but leaks
var children: [Person] = [] {
didSet {
children.forEach { $0.parent = self }
}
}
init(name: String) {
self.name = name
print("initialized \(name)")
}
deinit {
print("deinit \(name)")
}
var description: String {
return name
}
}
do {
let frank = Person(name: "Frank")
let lisa = Person(name: "Lisa")
frank.children = [lisa] /// KABOOM!
}
More information about the swift-users
mailing list