[swift-users] access violation when weak variable
Zhao Xin
owenzx at gmail.com
Sun Jul 10 00:10:36 CDT 2016
You code works fine in Xcode 7.3.1 (7D1014). So it must be a bug in Xcode 8.
Zhaoxin
On Sat, Jul 9, 2016 at 10:18 PM, Ray Fix via swift-users <
swift-users at swift.org> wrote:
>
> 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!
> }
>
> _______________________________________________
> swift-users mailing list
> swift-users at swift.org
> https://lists.swift.org/mailman/listinfo/swift-users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-users/attachments/20160710/ff7924bb/attachment.html>
More information about the swift-users
mailing list