Re: [swift-users] Protocol conformance error

2018-01-17 Thread Nevin Brackett-Rozinsky via swift-users
Because it would break this: func foo (c: T, a: U) { c.test(a) } Nevin On Wed, Jan 17, 2018 at 2:29 AM, Roshan via swift-users < swift-users@swift.org> wrote: > Hi, > > Here is some sample code that gives a protocol conformance error in a > playground: > > protocol A {} > protocol B: A {} > >

Re: [swift-users] appending packed bytes to [UInt8]

2018-01-10 Thread Nevin Brackett-Rozinsky via swift-users
Conversely, since I’m pretty sure the memory layout of a *tuple* is guaranteed to be as it appears, I would probably start with something like this: typealias Vec3rgba = (x: Float, y: Float, z: Float, r: Int8, g: Int8, b: Int8, a: Int8) Nevin On Wed, Jan 10, 2018 at 4:27 PM, Jens Persson via

Re: [swift-users] Rethrows issue

2017-12-30 Thread Nevin Brackett-Rozinsky via swift-users
So, I know this doesn’t actually address your issue, but I think it is important to clarify that “rethrows” does not guarantee anything about the *type* of error thrown by a function. What “rethrows” implies is that the function *will not throw* unless at least one of its arguments throws. In

Re: [swift-users] Incorrect Fisher-Yates shuffle in example code

2017-12-17 Thread Nevin Brackett-Rozinsky via swift-users
int the implementation is much sleeker.) Nevin On Sun, Dec 17, 2017 at 9:26 PM, Nevin Brackett-Rozinsky < nevin.brackettrozin...@gmail.com> wrote: > On Sun, Dec 17, 2017 at 7:37 PM, Dave Abrahams <dabrah...@apple.com> > wrote: > >> >> On Dec 16, 2017, at 4:34 PM, Nev

Re: [swift-users] Incorrect Fisher-Yates shuffle in example code

2017-12-17 Thread Nevin Brackett-Rozinsky via swift-users
On Sun, Dec 17, 2017 at 7:37 PM, Dave Abrahams <dabrah...@apple.com> wrote: > > On Dec 16, 2017, at 4:34 PM, Nevin Brackett-Rozinsky via swift-users < > swift-users@swift.org> wrote: > > public extension MutableCollection where Self: RandomAccessCollect

Re: [swift-users] Incorrect Fisher-Yates shuffle in example code

2017-12-16 Thread Nevin Brackett-Rozinsky via swift-users
On Sat, Dec 16, 2017 at 7:37 PM, Daniel Dunbar wrote: > Would you like to post a PR to fix these issues? > > - Daniel > All right, I’ve submitted a PR that I think should work, though I’m not too confident in the pre-Swift-4 parts (credit to swiftdoc.org if the code

[swift-users] Incorrect Fisher-Yates shuffle in example code

2017-12-16 Thread Nevin Brackett-Rozinsky via swift-users
The example implementation of the Fisher-Yates shuffle found here on Apple’s GitHub (and linked from swift.org/package-manager) has some problems. Stripping it down to just the Swift 4

[swift-users] Comprehensive documentation for Collection?

2017-12-15 Thread Nevin Brackett-Rozinsky via swift-users
In Xcode if I write, extension Collection { var secondIndex: Index { return index(after: startIndex) } } and then option-click on “Index”, it shows “associatedtype Index : Comparable” followed by a description. Is this documented somewhere? When I look at the documentation for Collection

[swift-users] Is SwiftDoc.org still being updated?

2017-10-17 Thread Nevin Brackett-Rozinsky via swift-users
This might be out of scope for Swift Users, but I was wondering if anyone knows whether SwiftDoc.org is still being maintained. As far as I can tell, it has not been updated for Swift 4 (even under “nightly build” it doesn’t show, eg. the Numeric protocol). I have found

Re: [swift-users] difference between two Ranges

2017-09-20 Thread Nevin Brackett-Rozinsky via swift-users
I think you’ll have to write this functionality yourself. If you start with one range and remove from it everything in another range, you will end up with either: i) An empty range, if the first is entirely within the second. ii) A single range, which might be closed, open, or half-open on

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

2017-09-11 Thread Nevin Brackett-Rozinsky via swift-users
Hi, quick question here: 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] What is up with names not being Strings any more in Swift 4?

2017-07-17 Thread Nevin Brackett-Rozinsky via swift-users
Could / should these types be ExpressibleByStringLiteral? Nevin On Mon, Jul 17, 2017 at 12:47 PM, Manfred Schubert via swift-users < swift-users@swift.org> wrote: > > > Am 17.07.2017 um 18:08 schrieb Jon Shier : > > > > Making them an extension on String makes them visible

Re: [swift-users] ⁨Is it possible to store a set of heterogeneous items with protocol?

2017-07-16 Thread Nevin Brackett-Rozinsky via swift-users
The standard pattern for type-erasure in Swift looks like this: protocol Farm { associatedtype Produce func grow() -> Produce } private class _AnyFarmBase : Farm { func grow() -> T { fatalError() } } private final class _AnyFarmBox: _AnyFarmBase { var farm: U init(_ x: U) {

Re: [swift-users] Swift Documentation question

2017-07-01 Thread Nevin Brackett-Rozinsky via swift-users
On Sat, Jul 1, 2017 at 4:36 PM, Jon Shier via swift-users < swift-users@swift.org> wrote: > swiftdoc.org should be integrated into swift.org and be kept officially > up to date. > I agree. Unfortunately it doesn’t have Swift 4 coverage yet, which is a shame, as I > like that documentation

Re: [swift-users] override-like keyword for default implementations

2017-05-16 Thread Nevin Brackett-Rozinsky via swift-users
On Tue, May 16, 2017 at 4:59 PM, Vladimir.S via swift-users < swift-users@swift.org> wrote: > On May 16, 2017, at 12:32 PM, Nevin Brackett-Rozinsky via swift-users < > swift-users@swift.org <mailto:swift-users@swift.org>> wrote: > >> There is not. >> &g

Re: [swift-users] override-like keyword for default implementations

2017-05-16 Thread Nevin Brackett-Rozinsky via swift-users
There is not. At some point in the future, I believe the plan is to eventually allow default implementations to be written in-line within the protocol declaration itself. In other words, the fact that default implementations currently must appear in extensions, is a temporary limitation that has

[swift-users] How to reference a generic function when a concrete version also exists?

2017-05-02 Thread Nevin Brackett-Rozinsky via swift-users
If I write a generic function like this: func f(_ x: T) { print("Generic: \(x)") } I can pass it to another function like this: func g(_ fn: (Int) -> Void) { fn(0) } g(f)// Prints “Generic: 0” However if I *also* write a non-generic function like this: func f(_ x: Int) { print("Int:

[swift-users] Error creating empty array of chained associated type

2017-04-29 Thread Nevin Brackett-Rozinsky via swift-users
I’ve stumbled upon an odd situation where Swift gives a compiler error if I do things directly, but works properly with no error if I first create a typealias. Here is a stripped-down example: protocol P { associatedtype C: Collection } extension P { func emptyArray() ->

Re: [swift-users] How do I turn an array into a bitmap image?

2017-03-16 Thread Nevin Brackett-Rozinsky via swift-users
Thanks Brent, that helps a lot. I eventually found a site (here if anyone’s interested) that describes (albeit in Objective-C) how to make a CGImage from a byte buffer through the use of CGDataProvider. Hopefully I’ll be able to put the pieces together

Re: [swift-users] How do I turn an array into a bitmap image?

2017-03-15 Thread Nevin Brackett-Rozinsky via swift-users
> On Mar 15, 2017, at 11:07 AM, Nevin Brackett-Rozinsky via swift-users < > swift-users@swift.org> wrote: > > Ideally I’d like to create the bitmap image without having to allocate a > second buffer. The sole purpose of the Float array is for creating this > image, so I

Re: [swift-users] How do I turn an array into a bitmap image?

2017-03-15 Thread Nevin Brackett-Rozinsky via swift-users
> On Mar 15, 2017, at 9:56 AM, Nevin Brackett-Rozinsky via swift-users < > swift-users@swift.org> wrote: > > For one of my programs, I need to take an array of Floats and use the > underlying bytes as the RGBA data for a bitmap image. In particular, the 32 > bits of each F

[swift-users] How do I turn an array into a bitmap image?

2017-03-15 Thread Nevin Brackett-Rozinsky via swift-users
For one of my programs, I need to take an array of Floats and use the underlying bytes as the RGBA data for a bitmap image. In particular, the 32 bits of each Float must be treated as the color of the corresponding pixel. So the result is an image of height 1 and width the length of the array. In

Re: [swift-users] Using 'SomeProtocol' as a concrete type conforming to protocol 'SomeProtocol' is not supported

2016-12-28 Thread Nevin Brackett-Rozinsky via swift-users
It will work if you change the enum declaration to: enum ElementNode In other words, let the enum hold arbitrary unconstrained associated types, and then make your APIs utilize instances of the enum with the associated type constrained to a protocol. The specific example you provide is

Re: [swift-users] Decimal to Double?

2016-11-28 Thread Nevin Brackett-Rozinsky via swift-users
On Mon, Nov 28, 2016 at 2:21 PM, Joe Groff via swift-users < swift-users@swift.org> wrote: > ExpressibleByFloatLiteral uses a binary float initial value and so doesn't > guarantee decimal accuracy That seems like a flaw in ExpressibleByFloatLiteral that should be fixed. Did anyone ever submit

Re: [swift-users] Bool to Int

2016-11-21 Thread Nevin Brackett-Rozinsky via swift-users
I don’t see what there is to be confused about. A “literal” is literally a bunch of characters in source code. The compiler interprets those characters as representing whatever type is appropriate to the context. For the case at hand, a boolean literal can be interpreted as any type which

Re: [swift-users] Decimal imported as NSDecimal not NSDecimalNumber in Swift 3 to Objective C

2016-11-14 Thread Nevin Brackett-Rozinsky via swift-users
Literals in Swift do not inherently have a type (at least conceptually). They are simply literals. The compiler will interpret them as whatever ExpressibleBy_Literal type is required to make the expression sensible. There are default types which literals will become if no type information is

Re: [swift-users] The value of enums

2016-11-06 Thread Nevin Brackett-Rozinsky via swift-users
To the topic at hand, the project I’m currently working on has 2 enums, both with String raw values. For comparison, it has 3 classes (a Formatter subclass, the app delegate, and one more), 4 protocols, and 47 structs. One of the enums exists to select among the handful of struct types which

Re: [swift-users] Overload by return type optionality?

2016-10-13 Thread Nevin Brackett-Rozinsky via swift-users
It works if you specify the types of the variables: let a: String = … if let b: String = … Nevin On Thu, Oct 13, 2016 at 5:36 PM, Rick Mann via swift-users < swift-users@swift.org> wrote: > It seems I can write this: > > extension String > { > public func deleting(prefix inPrefix: String)

Re: [swift-users] How to be DRY on ranges and closed ranges?

2016-10-12 Thread Nevin Brackett-Rozinsky via swift-users
You could also create a “Range” protocol with “lowerBound” and “upperBound” properties. Conform all the range types to it, and make your function take generic over the protocol. Nevin On Wed, Oct 12, 2016 at 7:21 PM, Hooman Mehr via swift-users < swift-users@swift.org> wrote: > I recommend

Re: [swift-users] private vs. fileprivate on global declaration in Swift3?

2016-09-28 Thread Nevin Brackett-Rozinsky via swift-users
To answer the original question: at file scope the access modifiers `private` and `fileprivate` have exactly the same effect. It does not matter which of them you use there. Nevin On Wed, Sep 28, 2016 at 12:14 PM, Marco S Hyman via swift-users < swift-users@swift.org> wrote: > > > On Sep 28,