Re: [swift-users] optional variable with ternary operator

2017-05-08 Thread Saagar Jha via swift-users
This functionality was removed via SE-0121, back in the Swift 3 timeframe. Saagar Jha > On May 8, 2017, at 19:49, Zhao Xin wrote: > > I wonder if it has ever been allowed? I am using Xcode and it never allows > that. > For you specific question, you can use > > var

Re: [swift-users] Help! Slicing an array is very expensive

2017-05-08 Thread Kelvin Ma via swift-users
Depending on what you’re trying to do with the data, you might be better off using an UnsafeBufferPointer and allocating and reallocating that, C-style. On Mon, May 8, 2017 at 7:01 PM, Philippe Hausler via swift-users < swift-users@swift.org> wrote: > I wonder if Data might be a better tool for

Re: [swift-users] Help! Slicing an array is very expensive

2017-05-08 Thread Zhao Xin via swift-users
Have you try other approaches? Maybe just write your data to cache on disk and read it back will be quicker? Zhaoxin On Tue, May 9, 2017 at 8:01 AM, Philippe Hausler via swift-users < swift-users@swift.org> wrote: > I wonder if Data might be a better tool for the job here since it is it’s > own

Re: [swift-users] optional variable with ternary operator

2017-05-08 Thread Zhao Xin via swift-users
I wonder if it has ever been allowed? I am using Xcode and it never allows that. For you specific question, you can use var number:Int? let result = (number ?? -1) > 0 ? 1 : 2 Zhaoxin On Tue, May 9, 2017 at 1:39 AM, Erica Sadun via swift-users < swift-users@swift.org> wrote: > I believe this

Re: [swift-users] Help! Slicing an array is very expensive

2017-05-08 Thread Philippe Hausler via swift-users
I wonder if Data might be a better tool for the job here since it is it’s own slice type and would avoid copying large amounts of data into temporary buffers. > On May 8, 2017, at 16:47, Rick Mann via swift-users > wrote: > > I have this C library that interacts with

[swift-users] Help! Slicing an array is very expensive

2017-05-08 Thread Rick Mann via swift-users
I have this C library that interacts with some hardware over the network that produces a ton of data. It tells me up front the maximum size the data might be so I can allocate a buffer for it, then does a bunch of network requests downloading that data into the buffer, then tells me when it's

[swift-users] discardable function start?

2017-05-08 Thread J.E. Schotsman via swift-users
Hello, I’ve got a compiler warning from hell (actually this is XCGLogger code): @discardableResult open func add(item: String) -> Bool { return itemsToMatch.insert(item).inserted } open func add(items: S) where S.Iterator.Element == String { for item in items {

Re: [swift-users] Making Error sub-enums Equatable

2017-05-08 Thread Zhao Xin via swift-users
I think you'd better define your own operator, maybe `=~` or something else. As `==` has already meant something in enum. Zhaoxin On Mon, May 8, 2017 at 5:07 PM, Rien via swift-users wrote: > I’d love to know if there is a better way, but a ‘switch’ or 'if case' is > the

Re: [swift-users] Making Error sub-enums Equatable

2017-05-08 Thread Rien via swift-users
I’d love to know if there is a better way, but a ‘switch’ or 'if case' is the only way I know. Regards, Rien Site: http://balancingrock.nl Blog: http://swiftrien.blogspot.com Github: http://github.com/Balancingrock Project: http://swiftfire.nl - A server for websites build in Swift > On

[swift-users] Making Error sub-enums Equatable

2017-05-08 Thread Rick Mann via swift-users
Seriously, I've been googling this for a half-hour, and I can't find an answer (everything that comes up is for ErrorType, absolutely nothing for Error). I have an enum: enum MyErrors : Error { case one(String) case two case three(String) } let a: MyErrors = .one("foo") let b =