[swift-users] Set size of byte array

2016-08-04 Thread KS Sreeram via swift-users
Hello I’m trying to initialize a byte-array efficiently with minimal copying with the following steps: 1. Create an empty byte array. 2. Reserve sufficient capacity in the array. 3. Use mutable pointers into the array to fill in the data. 4. The actual size that was filled is known only after it

Re: [swift-users] Assertion Failure When Using the swift-DEVELOPMENT-SNAPSHOT-2016-08-04-a Xcode Toolchain

2016-08-04 Thread Mark Lacey via swift-users
> On Aug 4, 2016, at 8:51 PM, Saagar Jha via swift-users > wrote: > > Hello Swift Users, > > This afternoon I updated my Xcode to Xcode 8 beta 4, and tried to compile one > of my previously migrated Swift 3 projects. Along with a couple of renames, > the compiler kept crashing due to a segme

[swift-users] Assertion Failure When Using the swift-DEVELOPMENT-SNAPSHOT-2016-08-04-a Xcode Toolchain

2016-08-04 Thread Saagar Jha via swift-users
Hello Swift Users, This afternoon I updated my Xcode to Xcode 8 beta 4, and tried to compile one of my previously migrated Swift 3 projects. Along with a couple of renames, the compiler kept crashing due to a segmentation fault. Since the issue appeared to be similar to SR-2227, which was suppo

Re: [swift-users] Cleaner way than if let initialization?

2016-08-04 Thread Zhao Xin via swift-users
Thank you. I think this is the best I saw today. Zhaoxin On Fri, Aug 5, 2016 at 5:24 AM, Erica Sadun via swift-users < swift-users@swift.org> wrote: > And Greg from Omni Group has an even better solution for you. Since > DateFormatter inherits from Formatter, you can use its `string(for:)` whic

Re: [swift-users] 2016-08-04-a-osx snapshot corrupt?

2016-08-04 Thread Jose Cheyo Jimenez via swift-users
A nice person at apple told me a work around. Just quit Xcode and it will work. :) > On Aug 4, 2016, at 5:47 PM, Jose Cheyo Jimenez wrote: > > swift-DEVELOPMENT-SNAPSHOT-2016-08-04-a-osx > > What is going on here? Why is the image not signed? Anybody having the same > issues? > > I’ve dow

Re: [swift-users] 2016-08-04-a-osx snapshot corrupt?

2016-08-04 Thread Mikio Takeuchi via swift-users
I have no problem with it. $ md5 swift-DEVELOPMENT-SNAPSHOT-2016-08-04-a-osx.pkg MD5 (swift-DEVELOPMENT-SNAPSHOT-2016-08-04-a-osx.pkg) = 0f572feecca36ffc5f6a045319845875 -- Mikio 2016-08-05 9:47 GMT+09:00 Jose Cheyo Jimenez via swift-users < swift-users@swift.org>: > swift-DEVELOPMENT-SNAPSHOT-

[swift-users] 2016-08-04-a-osx snapshot corrupt?

2016-08-04 Thread Jose Cheyo Jimenez via swift-users
swift-DEVELOPMENT-SNAPSHOT-2016-08-04-a-osx What is going on here? Why is the image not signed? Anybody having the same issues? I’ve download it multiple times. Aug 4 14:32:14 MacBook Installer[1580]: Error parsing distribution script from data Aug 4 14:32:14 MacBook xmllint[1586]: -:1: par

Re: [swift-users] build-toolchain failing

2016-08-04 Thread David Liu via swift-users
Thanks Mishal! My fault I did not install the latests Xcode, thanks again for the help! Everything is building fine now. I do have another question was wondering if you had any tips. I am currently debugging the toolchain via REPL, creating a test function and setting a break point 1> func test()

Re: [swift-users] Cleaner way than if let initialization?

2016-08-04 Thread Erica Sadun via swift-users
And Greg from Omni Group has an even better solution for you. Since DateFormatter inherits from Formatter, you can use its `string(for:)` which accepts optionals: let dobString3 = serverDateFormatter.string(for:dob) ?? "" -- E > On Aug 4, 2016, at 3:17 PM, Erica Sadun via swift-users > wrot

Re: [swift-users] Cleaner way than if let initialization?

2016-08-04 Thread Erica Sadun via swift-users
> On Aug 4, 2016, at 1:41 PM, Tim Vermeulen via swift-users > wrote: > > You want `flatMap`: > > let dobString = dob.flatMap(serverDateFormatter.stringFromDate) > > Or if you want `dobString` to be non-optional: > > let dobString = dob.flatMap(serverDateFormatter.stringFromDate) ?? “" You c

Re: [swift-users] Cleaner way than if let initialization?

2016-08-04 Thread Erica Sadun via swift-users
> On Aug 4, 2016, at 11:32 AM, Daniel Tartaglia via swift-users > wrote: > > Currently I do stuff like this: > > let dobString: String > if let dob = dob { > dobString = serverDateFormatter.stringFromDate(dob) > } > else { > dobString = "" > } > > Is there a better, more idiomatic

Re: [swift-users] Cleaner way than if let initialization?

2016-08-04 Thread Daniel Tartaglia via swift-users
Thanks Tim! > On Aug 4, 2016, at 3:41 PM, Tim Vermeulen wrote: > > You want `flatMap`: > > let dobString = dob.flatMap(serverDateFormatter.stringFromDate) > > Or if you want `dobString` to be non-optional: > > let dobString = dob.flatMap(serverDateFormatter.stringFromDate) ?? “" > >> Current

Re: [swift-users] Cleaner way than if let initialization?

2016-08-04 Thread Saagar Jha via swift-users
Oh, wait, I can’t read. Ignore that; then there’s no easy way to do it. Saagar Jha > On Aug 4, 2016, at 12:42, Saagar Jha wrote: > > Ahh…then optional chaining is the way to go: `let dobString = > serverDateFormatter?.stringFromDate(dob) ?? ""` > > Saagar Jha > > > >> On Aug 4, 2016, at

Re: [swift-users] Cleaner way than if let initialization?

2016-08-04 Thread Saagar Jha via swift-users
Ahh…then optional chaining is the way to go: `let dobString = serverDateFormatter?.stringFromDate(dob) ?? ""` Saagar Jha > On Aug 4, 2016, at 12:41, Daniel Tartaglia wrote: > > That’s not possible. stringFromDate requires an NSDate, but dob is an > optional > >> On Aug 4, 2016, at 2:59 PM,

Re: [swift-users] Cleaner way than if let initialization?

2016-08-04 Thread Tim Vermeulen via swift-users
This doesn’t work because `dob` is optional and `stringFromDate` only takes a non-optional date. > That’s where I would use the ?? operator: > > let dobString = serverDateFormatter.stringFromDate(dob) ?? "" > > > Jeff Kelley > > slauncha...@gmail.com(mailto:slauncha...@gmail.com)|@SlaunchaMan

[swift-users] Cleaner way than if let initialization?

2016-08-04 Thread Tim Vermeulen via swift-users
You want `flatMap`: let dobString = dob.flatMap(serverDateFormatter.stringFromDate) Or if you want `dobString` to be non-optional: let dobString = dob.flatMap(serverDateFormatter.stringFromDate) ?? “" > Currently I do stuff like this: > > letdobString:String > ifletdob = dob { > dobString =ser

Re: [swift-users] Cleaner way than if let initialization?

2016-08-04 Thread Daniel Tartaglia via swift-users
That’s not possible. stringFromDate requires an NSDate, but dob is an optional > On Aug 4, 2016, at 2:59 PM, Saagar Jha wrote: > > As such, there shouldn’t be a need for an if; `let dobString = > serverDateFormatter.stringFromDate(dob)` should be sufficient. > > Saagar Jha > > > >> On Aug

Re: [swift-users] Cleaner way than if let initialization?

2016-08-04 Thread Saagar Jha via swift-users
As such, there shouldn’t be a need for an if; `let dobString = serverDateFormatter.stringFromDate(dob)` should be sufficient. Saagar Jha > On Aug 4, 2016, at 11:55, Zhao Xin via swift-users > wrote: > > It can't be done by ?? as stringFromDate(Date) returns String instead of > String? > >

Re: [swift-users] Cleaner way than if let initialization?

2016-08-04 Thread Zhao Xin via swift-users
It can't be done by ?? as stringFromDate(Date) returns String instead of String? Zhaoxin On Fri, Aug 5, 2016 at 1:42 AM, Jeff Kelley via swift-users < swift-users@swift.org> wrote: > That’s where I would use the ?? operator: > > let dobString = serverDateFormatter.stringFromDate(dob) ?? "" > >

Re: [swift-users] build-toolchain failing

2016-08-04 Thread Mishal Shah via swift-users
Hi David, Which version of Xcode are you using? We now require Xcode 8 Beta 4 to be able to build swift. Also, please provide full error message. Thanks, Mishal Shah > On Aug 4, 2016, at 2:00 AM, David Liu via swift-users > wrote: > > I am getting errors compiling the toolchain from the tip

Re: [swift-users] Cleaner way than if let initialization?

2016-08-04 Thread Jeff Kelley via swift-users
That’s where I would use the ?? operator: let dobString = serverDateFormatter.stringFromDate(dob) ?? "" Jeff Kelley slauncha...@gmail.com | @SlaunchaMan | jeffkelley.org > On Aug 4, 2016, at 1:32 PM, Daniel Tartaglia via swift-users >

[swift-users] Cleaner way than if let initialization?

2016-08-04 Thread Daniel Tartaglia via swift-users
Currently I do stuff like this: let dobString: String if let dob = dob { dobString = serverDateFormatter.stringFromDate(dob) } else { dobString = "" } Is there a better, more idiomatic, way to do this sort of thing? ___ swift-users mail

[swift-users] build-toolchain failing

2016-08-04 Thread David Liu via swift-users
I am getting errors compiling the toolchain from the tip of master. Specifically inside of stdlib/SDK/.., it has some syntax issue which leads to compilation failure. I did a swift/utils/update-checkout then swift/utils/build-toolchain. I see the CI builds are green, am I out of sync some where? A

Re: [swift-users] generic function called recursively not compiling

2016-08-04 Thread Kevin Nattinger via swift-users
Looks like a bug in the type inference system to me, but I’ll let someone with a better knowledge of the compiler confirm. Meanwhile, you can work around by explicitly casting any of the pieces of the return statement to `[Element]` or using a temporary for one or more of them. let middle =

[swift-users] generic function called recursively not compiling

2016-08-04 Thread Ray Fix via swift-users
I filed rdar://27700622 and attached a playground. Any workaround magic I can do here? func quickSort(_ input: [Element]) -> [Element] { if input.count < 2 { return input } let pivot = input.first! let left = input.dropFirst().filter { $0 <= pivot } let right = inpu

[swift-users] try? priority

2016-08-04 Thread J.E. Schotsman via swift-users
I was surprised when I got a compiler error for this code: if try? MyThrowingFunction() != nil {…} (MyThrowingFunction does not return an optional value) This compiles: if (try? MyThrowingFunction) != nil {…} (Xcode 7.3.1) Shouldn’t try? have higher priority than != here? Please disre

Re: [swift-users] non-mutating func that still mutates a struct, compiler not aware

2016-08-04 Thread Brent Royal-Gordon via swift-users
> On Aug 4, 2016, at 1:25 AM, Raphael Sebbe via swift-users > wrote: > > My understanding is that the compiler doesn't make a real copy in the acopy = > self instruction, and then provides that contents to the mx_gels_ function > which modifies the memory contents. > > > public func solve(r

Re: [swift-users] Date and Data

2016-08-04 Thread Quinn "The Eskimo!" via swift-users
On 3 Aug 2016, at 23:43, Travis Griggs via swift-users wrote: > I realized right after I wrote this, that I could also > > typealias Timestamp = Date > > And reap similar benefits. Yeah, of the two NSDate is the one that’s misnamed IMO. The name gives the impression that the value is someh

[swift-users] non-mutating func that still mutates a struct, compiler not aware

2016-08-04 Thread Raphael Sebbe via swift-users
In the example below, solve is a non-mutating func within struct type Matrix, that uses an Array to store its values. This function mutates self, even though it's declared as non-mutating. My understanding is that the compiler doesn't make a real copy in the acopy = self instruction, and then pr