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
}
}
> 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
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
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:
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"
}
}
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.
>
>
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
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
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
}
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
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
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
> 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),
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
> 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
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
16 matches
Mail list logo