Re: [swift-users] Dictionary with optional values

2016-05-18 Thread Jens Alfke via swift-users
> On May 18, 2016, at 7:35 PM, Nathan Day wrote: > > In objective-c I have come across something like this a lot where a > NSDictionary has been created from JSON an a NSNull is used to represent an > actual null in the source JSON versus the absence of the key Yeah, this comes from JavaScrip

Re: [swift-users] Dictionary with optional values

2016-05-18 Thread Nathan Day via swift-users
In objective-c I have come across something like this a lot where a NSDictionary has been created from JSON an a NSNull is used to represent an actual null in the source JSON versus the absence of the key, most of the time I have had to just convert the NSNull to a nil, but I did have a situatio

Re: [swift-users] Dictionary with optional values

2016-05-18 Thread David Sweeris via swift-users
This isn't limited to Optional. Any dictionary whose value type conforms to NilLiteralConvertible can be "vulnerable" to some pretty subtle bugs. - Dave Sweeris > On May 18, 2016, at 13:16, Jens Alfke via swift-users > wrote: > > (Thinking about it, I can’t see much use for a dictionary of op

Re: [swift-users] Dictionary with optional values

2016-05-18 Thread Jordan Rose via swift-users
> On May 18, 2016, at 09:38, Ray Fix via swift-users > wrote: > > >> On May 18, 2016, at 3:56 AM, Artyom Goncharov via swift-users >> wrote: >> >> var noOptDict = ["one": 1, "two": 2, "three": 3 ] >> noOptDict["one"] = nil > > Wow, interesting. To me this was surprising behavior too. > >

[swift-users] file io in Swift 2.2 for Linux (would like to be pointed in the right direction)

2016-05-18 Thread John Myers via swift-users
I've been having trouble figuring out how to read and write data to a textfile, and not finding much out there for Swift on Linux. I found code for reading data from a file on StackOverflow that works for me, but cludged together my own code for writing to a file. I'm not sure exactly what I'm do

Re: [swift-users] Dictionary with optional values

2016-05-18 Thread Marco S Hyman via swift-users
> On May 18, 2016, at 11:03 AM, Artyom Goncharov via swift-users > wrote: > > Yes, of course I can use API method but this kind of behaviour for subscript > operator seems inconsistent(or even magical) to me because it is possible to > initialise a dictionary with nil without casting it. Thou

Re: [swift-users] Dictionary with optional values

2016-05-18 Thread Jens Alfke via swift-users
> On May 18, 2016, at 11:03 AM, Artyom Goncharov via swift-users > wrote: > > Yes, of course I can use API method but this kind of behaviour for subscript > operator seems inconsistent(or even magical) to me because it is possible to > initialise a dictionary with nil without casting it. Thou

[swift-users] Dictionary with optional values

2016-05-18 Thread Artyom Goncharov via swift-users
Yes, of course I can use API method but this kind of behaviour for subscript operator seems inconsistent(or even magical) to me because it is possible to initialise a dictionary with nil without casting it. Though nil is a special case it is still a value in the set of all values of a T? type, a

Re: [swift-users] Member wise initializer doesn't work with default-initialized const properties

2016-05-18 Thread Jens Alfke via swift-users
> On May 17, 2016, at 7:48 AM, Neil Faiman via swift-users > wrote: > > “You can provide a default value for a stored property as part of its > definition, as described in Default Property Values. You can also set and > modify the initial value for a stored property during initialization. Thi

Re: [swift-users] Dictionary with optional values

2016-05-18 Thread Ray Fix via swift-users
> On May 18, 2016, at 3:56 AM, Artyom Goncharov via swift-users > wrote: > > var noOptDict = ["one": 1, "two": 2, "three": 3 ] > noOptDict["one"] = nil Wow, interesting. To me this was surprising behavior too. The comment for Dictionary subscript says: /// Access the value associated w

[swift-users] Measuring time accurately on Linux

2016-05-18 Thread Michal Kalinowski via swift-users
It's my first time posting to users mailing list so hello everyone. I'm currently optimizing code of my server written in Swift. To do that reliably I want to be able to measure how long it takes to execute specific methods. On OSX I'm using mach_absolute_time() that I've wrapped in a struct f

Re: [swift-users] Member wise initializer doesn't work with default-initialized const properties

2016-05-18 Thread Neil Faiman via swift-users
> On May 17, 2016, at 7:03 AM, Jeremy Pereira > wrote: > > >> On 16 May 2016, at 22:37, Neil Faiman via swift-users >> wrote: >> >> Using the default Swift with Xcode 7.3.1. >> >> It appears that you cannot use the implicit memberwise initializer with a >> struct that has “let” properties

Re: [swift-users] Dictionary with optional values

2016-05-18 Thread 肇鑫 via swift-users
I think you should use updateValue forKey method instead of subscript=value. Subscript in Dictionary returns an Element?, you should not use it like a subscript in Array, which returns  Element. Zhaoxin Get Outlook for iOS _ From: Artyom Goncharov via swift-users

Re: [swift-users] Dictionary with optional values

2016-05-18 Thread David Sweeris via swift-users
I'm not in front of Xcode, so I can't confirm this, but I suspect that `optDict["one"] = nil as! Int?` will set "one" to nil, rather than removing "one". Whatever the rules for inferring the type of `nil` when an Optional is involved are, it seems like it always infers the one I don't want. H

[swift-users] Dictionary with optional values

2016-05-18 Thread Artyom Goncharov via swift-users
Hi, here is the playground snippet: var noOptDict = ["one": 1, "two": 2, "three": 3 ] noOptDict["one"] = nil noOptDict // “one” is gone var optDict: [String: Int?] = ["one": 1, "two": 2, "three": nil] optDict["one"] = nil optDict // “one” is gone but “three” is still there So the first dict inst