Re: [swift-users] Should I be using more catchless do blocks?

2017-06-19 Thread Rien via swift-users
Yes. But: Only if it makes the code better. I think that “understandability engineering” is just as important as “software engineering”. Maybe more so. After all, code that we understand has a better chance of working correctly than code that follows all paradigms but once the developer is

Re: [swift-users] Should I be using more catchless do blocks?

2017-06-19 Thread Michael Savich via swift-users
Huh, I didn't realize you could nest functions like that. That being said, I'm not sure the declare-then-use structure really appeals to me personally. I might use it if the function was getting really long. One last question: labels on do blocks. I know they are mostly intended to be used for

Re: [swift-users] Protocol Conformance

2017-06-19 Thread Karl Wagner via swift-users
> On 20. Jun 2017, at 01:38, Muhammad Tahir Vali via swift-users > wrote: > > Hey all, > > I wanted to know if theres a work around for a problem I am having > > lets say I have a protocol > > protocol Graphable : CustomStringConvertible, Sequence, Collection { >

Re: [swift-users] Extensions on Typealiased Existential Protocols

2017-06-19 Thread Steven Brunwasser via swift-users
@David But the automatic conformance is currently supported through extension A where Self: B. @Slava When does extension A where Self: B not equal extension B where Self: A? Why would protocol inheritance not be communicative? On June 19, 2017 at 5:26:44 PM, David Sweeris (daveswee...@mac.com)

[swift-users] Protocol Conformance

2017-06-19 Thread Muhammad Tahir Vali via swift-users
Hey all, I wanted to know if theres a work around for a problem I am having lets say I have a protocol protocol *Graphable* : CustomStringConvertible, Sequence, Collection { var vertices : [AnyVertexable] { get set } *var edges: [AnyEdge]? { get set }* } Then I have

Re: [swift-users] Should I be using more catchless do blocks?

2017-06-19 Thread Michael Ilseman via swift-users
> On Jun 19, 2017, at 11:47 AM, Michael Savich wrote: > > Yeah, it's all about balance to be sure. Though one benefit of do blocks is > in functions that are tied to a sense of time. It seems to me that the in > case of something like viewDidLoad separating code into

Re: [swift-users] Extensions on Typealiased Existential Protocols

2017-06-19 Thread Jon Shier via swift-users
What I usually do here is: typealias CProtocol = A & B protocol C: CProtocol { } // or just A & B directly, I think extension C {} So it’s a bit silly to me. Jon > On Jun 19, 2017, at 3:44 PM, Slava Pestov via swift-users > wrote: > > Hi Steven, > >> On Jun 19,

[swift-users] Extensions on Typealiased Existential Protocols

2017-06-19 Thread Steven Brunwasser via swift-users
Is this error intentional, or a bug? protocol A {} protocol B {} typealias C = A & B // valid extension C {} // Error: Non-nominal type 'C' (aka 'A & B') cannot be extended extension A where Self: B {} // valid struct Foo: C {} // valid Since extension A where Self: B is the same as

Re: [swift-users] Should I be using more catchless do blocks?

2017-06-19 Thread Michael Ilseman via swift-users
Introducing scope to manage lifetimes of local variables is a useful and valuable practice. Note that it might also be an opportunity to refactor the code. Any do block you want to introduce could also be a local function definition that you call later. Alternatively, it could be generalized

Re: [swift-users] Restricting associated values

2017-06-19 Thread Karl Wagner via swift-users
> On 19. Jun 2017, at 04:30, Nevin Brackett-Rozinsky via swift-users > wrote: > > Is there a way to restrict the associated values of an enum? For example, > suppose I have this type: > > enum Angle { > case radians(Double) > case degrees(Double) > } > > I

Re: [swift-users] Restricting associated values

2017-06-19 Thread Karl Wagner via swift-users
> On 19. Jun 2017, at 20:03, Karl Wagner wrote: > > >> On 19. Jun 2017, at 04:30, Nevin Brackett-Rozinsky via swift-users >> > wrote: >> >> Is there a way to restrict the associated values of an enum? For example, >>

[swift-users] Is there any way to decode from Any type JSON Object using JSONDecoder?

2017-06-19 Thread Masaki Haga via swift-users
Hi Swift-Users, I was wondering if there is any way to decode JSON from Any type JSON Object using `JSONDecoder`, not from Data type object. Currently, `JSONDecoder` has only one decode function which decodes Data type object to `Decodable`. Inside the function, it serializes Data object to Any

[swift-users] Should I be using more catchless do blocks?

2017-06-19 Thread Michael Savich via swift-users
So, something I did not know until recently is that do blocks in Swift are for more than just error handling, they can also be used to tighten scope. I'm wondering, why not use a ton of do blocks? Like, if I have a ViewController lifecycle method like viewDidLoad, I could segment it into out a

Re: [swift-users] Restricting associated values

2017-06-19 Thread Travis Griggs via swift-users
> On Jun 18, 2017, at 10:33 PM, Howard Lovatt via swift-users > wrote: > > To me Angle is a unit with two common representations: radians and degrees. > It's not an enum because it doesn't have two values, it has one value that > you can view in two ways. > >