[swift-users] UINavigationController subclass leaks member variable memory

2017-12-13 Thread 吴君恺 via swift-users
Hello community, I just encountered a pretty weird behavior when I subclass `UINavigationController` without overriding any initializers. Simple Code: import UIKit class MyViewController: UINavigationController { let value: Int = { print("member init") return 3 }() }

Re: [swift-users] protocol definition question

2017-12-13 Thread Kevin Nattinger via swift-users
If you want to match [UInt8] specifically, just use the non-sugared definition: extension RawBits where RawValue == Array { } If you want it to match any array, that’s more complicated. As far as I’ve been able to work out, you have to wrap it in a protocol. Most of Array’s usefulness comes fr

[swift-users] protocol definition question

2017-12-13 Thread Frank Swarbrick via swift-users
I have the following: public protocol RawBits: CustomStringConvertible, Collection { associatedtype RawValue var rawValue: RawValue { get set } } extension RawBits where RawValue: FixedWidthInteger, RawValue: UnsignedInteger { [...fields and methods are defined here...] }

Re: [swift-users] Tuple of two or more instances to withExtendedLifetime

2017-12-13 Thread Jens Persson via swift-users
Ok, thanks! On Wed, Dec 13, 2017 at 10:20 PM, Andrew Trick wrote: > Yes, withExtendedLifetime is a generic API that guarantees the lifetime of > any non-trivial value. i.e. if the tuple contains a reference, the lifetime > of that reference will be extended. > > That said, there is a theoretical

Re: [swift-users] Tuple of two or more instances to withExtendedLifetime

2017-12-13 Thread Andrew Trick via swift-users
Yes, withExtendedLifetime is a generic API that guarantees the lifetime of any non-trivial value. i.e. if the tuple contains a reference, the lifetime of that reference will be extended. That said, there is a theoretical bug in the optimizer that you will be much more likely to hit in practice

Re: [swift-users] Tuple of two or more instances to withExtendedLifetime

2017-12-13 Thread Jordan Rose via swift-users
Good question and good thought! I believe the answer is yes, this will work as intended, but I'd like to get someone more versed in SIL than me to verify that. Andy? Jordan > On Dec 13, 2017, at 01:28, Jens Persson via swift-users > wrote: > > There are no restrictions on the type of the fi

[swift-users] Tuple of two or more instances to withExtendedLifetime

2017-12-13 Thread Jens Persson via swift-users
There are no restrictions on the type of the first argument to withExtendedLiftetime, even though it makes sense only for reference types. So both the below variants will compile, and my question is if the first one will work as expected (extending the lifetime of both a and b) or if the second va