Re: [swift-users] Re-initializing lazy vars

2017-10-21 Thread Joanna Carter via swift-users
Oops! forgot to add example code for resetting with non-optional public var : public struct TestStruct { private var _description: String? public var description: String { get { return _description ?? "" } set { _description = newValue } }

Re: [swift-users] Re-initializing lazy vars

2017-10-21 Thread Joanna Carter via swift-users
> It just seems so obvious to create-if-nil, and makes it nice to reset stuff > that should be re-created. In my case, after my NSURLSession gets > invalidated, I wanted to set the property to nil, and next time a session was > needed, it would just get created. The only thing I would query

Re: [swift-users] Can't implement generic subscript in protocol

2017-09-15 Thread Joanna Carter via swift-users
The answer to the segmentation fault is that I was trying to assign the subscript "method" to a closure var of the same signature. It would seem Swift doesn't allow this :-( Joanna -- Joanna Carter Carter Consulting ___ swift-users mailing list

Re: [swift-users] Can't implement generic subscript in protocol

2017-09-15 Thread Joanna Carter via swift-users
Xcode Version 9.0 (9A235) Hmmm. I'm now getting a segmentation fault : 11 on a constructor when trying to implement type erasure : protocol DataProvider { associatedtype ItemType subscript(index: Int) -> ItemType { get } } class _AnyDataProviderBoxBase: DataProvider { subscript(index:

[swift-users] Can't implement generic subscript in protocol

2017-09-15 Thread Joanna Carter via swift-users
Greetings Now we've got generic subscripts, I thought I'd play… protocol DataProvider { subscript(index: Int) -> itemType { get } } class Test : DataProvider // error : Type 'Test' does not conform to protocol 'DataProvider' { subscript(index: Int) -> String { return "Fred" } }

Re: [swift-users] Can you use @autoclosure in a setter?

2017-09-11 Thread Joanna Carter via swift-users
Greetings > I have a class with a property that needs to be really *really* lazy. So > lazy, in fact, that when you assign to that property, the class actually > stores a closure of what you assigned, which is only evaluated if and when > you actually attempt to read the property. > >

Re: [swift-users] CustomStringConvertible?

2017-09-09 Thread Joanna Carter via swift-users
Greetings > Thanks for your reply, Rien. I just tried this again, and now it seems that > either is acceptable. Seems a little weird, but I guess I’d rather have more > flexibility than less. > class GPS : Powerable, CustomStringConvertible { > // Either of these work > //var

Re: [swift-users] Still can't derive from a generic class

2017-09-01 Thread Joanna Carter via swift-users
Hi Joe Thanks for your input on this. > This is likely due to the runtime not handling cycles properly in type > metadata initialization—a subclass T needs its base class metadata for > BaseObject, which in turn needs the metadata for T to instantiate the > generic type. This is something we

Re: [swift-users] Still can't derive from a generic class

2017-08-30 Thread Joanna Carter via swift-users
Hi Kenny > Just curious, and because I have a distinct lack of imagination: can you > share a concrete case of this pattern? class BaseObject { private let properties: [PartialKeyPath : AnyProperty] init(properties: [PartialKeyPath : AnyProperty]) { self.properties = properties }

Re: [swift-users] Still can't derive from a generic class

2017-08-29 Thread Joanna Carter via swift-users
Hi Jon > Le 29 août 2017 à 19:20, Jon Shier a écrit : > > This works fine for me in a playground in the latest Xcode 9 beta: > > class Test { } > > class Base { } > > class Sub: Base { } > > let sub = Sub() That may well work but what I want is to be able to do is

[swift-users] Still can't derive from a generic class

2017-08-29 Thread Joanna Carter via swift-users
Hi I would have hoped by now that it should be possible to do : class BaseObject { } class Test : BaseObject { } All compiles well but, at runtime, when calling let test = Test(), I get a "EXC_BAD_INSTRUCTION (code=EXC_I386_INVOP, subcode=0x0)" error. This is something I have been able to do

Re: [swift-users] Question with calling a method which returns `Self` on super

2017-08-11 Thread Joanna Carter via swift-users
I really must do more research before making accusations ;-) > Which still leaves my question of why I have to reimplement the default > copy(other:) method from the protocol's extension in the base class ??? Apparently, the answer is to remove the declaration of the copy(other:) method from

Re: [swift-users] Question with calling a method which returns `Self` on super

2017-08-11 Thread Joanna Carter via swift-users
> here is the scenario, I want to implement a Copying protocol which can be > used homogeneously > > protocol Copying { > func copy() -> Self > } > > Because this protocol contains neither associated-type-requirements or > self-requirements(requiring a method returning Self is different),

Re: [swift-users] Constraining the conforming type of a protocol

2017-07-30 Thread Joanna Carter via swift-users
IMHO, there is a very subtle difference between : protocol Toggling : Equatable { … } extension Toggling { … } … and : protocol Toggling { … } extension Toggling where Self : Equatable { … } The first says that any type that implements Toggling also implements Equatable. The second

Re: [swift-users] Simultaneous accesses, but modification requires exclusive access

2017-07-24 Thread Joanna Carter via swift-users
> Background: > Just a little background into what I was trying to achieve (I could be wrong): > > - I have a set of classes C1, C2, C3 which has a lot of common code > > - I would like to build something that can be reused without exposing the > implementation details. (I can subclass but

[swift-users] Swift 4 emulating Decoder behaviour

2017-07-13 Thread Joanna Carter via swift-users
Greetings I notice that, with Swift 4, I can decode an object like this : • let retrievedSpot = try decoder.decode(ParkingSpot.self, from: retrievedData) And that will return a ParkingSpot, as expected, into retrievedSpot. However, I thought I would try the same technique with one