Dear swifters.

I have an proposal for autocreation of optional variables

This idea came from below situation

I have to addtional header to NSURLSessionConfiguration like this

let config = NSURLSessionConfiguration.defaultSessionConfiguration()
config.HTTPAdditionalHeaders?["Some-Additional-Info"] = "1992-08-01"

here is the problem

how to be sure not nil for HTTPAdditionalHeaders in
defaultSessionConfiguration

may be nil or not nil, I read api reference of HTTPAdditionalHeaders but,
did't see  for value state of creation.

yeah, I know. it's optional. so may be I should thought it must be nil. but
really must be? I think it's not very clear logic.

anyway, HTTPAdditionalHeaders was nil. so i have to solve, and solve like
this.

let config = NSURLSessionConfiguration.defaultSessionConfiguration()
var headers = config.HTTPAdditionalHeaders ?? [NSObject: AnyObject]()
headers["Some-Additional-Info"] = "1992-08-01"

May be another way to solve this.

*so I suggest autocreate parameter or something like that*

NSURLSessionConfiguration have this variable
public var HTTPAdditionalHeaders: [NSObject : AnyObject]?

*change above things to like below*

public *autocreate* var HTTPAdditionalHeaders: [NSObject : AnyObject]? {

*create* { return [NSObject: AnyObject]() }

}


let headers = config.HTTPAdditionalHeaders must be return nil

but

config.HTTPAdditionalHeaders["SomeThinkConvenient"] = "YEAH~"

this is automatically create Dictionary and set key and value


What about this idea, Dears?


Thank you for reading.
_______________________________________________
swift-evolution mailing list
[email protected]
https://lists.swift.org/mailman/listinfo/swift-evolution

Reply via email to