[swift-users] TWISt-shout Newsletter 2017-07-17

2017-07-16 Thread Kenny Leung via swift-users
Hi All. Here is your TWISt-shout Newsletter for the week of 2017-07-10 to 2017-07-16 https://github.com/pepperdog/TWISt-shout/blob/master/2017/TWISt-shout-2017-07-17.md Enjoy! -Kenny

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

2017-07-16 Thread Glen Huang via swift-users
Thanks for the code sample and link, but if I’m not wrong, this pattern doesn’t allow heterogeneous items. If I have these definitions: struct Chicken {} struct Pig {} class ChickenFarm: Farm { func grow() -> Chicken { return Chicken() } } class PigFarm: Farm { func grow()

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) {

[swift-users] Recommended way to write conditional compilation for 32- or 64-bit?

2017-07-16 Thread Jens Persson via swift-users
I need to define some datatypes differently depending on if the target is 32- or 64-bit. The code should compile on any 32- or 64-bit platform. Is the following the recommended way to do this? #if arch(x86_64) || arch(arm64) // Define the types, knowing that we're on a 64-bit platform.