<html><head><meta http-equiv="Content-Type" content="text/html charset=us-ascii"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div dir="auto" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">If the compiler can figure out the type of the expression, you can use [:] in place of [NSObject: AnyObject], as below:</div><div class=""><br class=""></div><div class="">let&nbsp;config =&nbsp;URLSessionConfiguration.default<br class="">var&nbsp;headers =&nbsp;config.httpAdditionalHeaders&nbsp;?? [:]<br class="">headers["Some-Additional-Info"] =&nbsp;"1992-08-01"</div><div class=""><br class=""><div class=""><div class=""><div class="">
<div style="color: rgb(0, 0, 0); letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">Saagar Jha<br class=""><br class=""><br class=""></div>

</div>
<br class=""><div><blockquote type="cite" class=""><div class="">On Jul 28, 2016, at 19:08, Kwanghoon Choi via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Dear swifters.&nbsp;<div class=""><br class=""></div><div class="">I have an proposal for autocreation of optional variables</div><div class=""><br class=""></div><div class="">This idea came from below situation</div><div class=""><br class=""></div><div class="">I have to addtional header to NSURLSessionConfiguration like this</div><div class=""><br class=""></div><div class="">let config = NSURLSessionConfiguration.defaultSessionConfiguration()</div><div class="">config.HTTPAdditionalHeaders?["Some-Additional-Info"] = "1992-08-01"</div><div class=""><br class=""></div><div class="">here is the problem</div><div class=""><br class=""></div><div class="">how to be sure not nil for HTTPAdditionalHeaders in defaultSessionConfiguration</div><div class=""><br class=""></div><div class="">may be nil or not nil, I read api reference of HTTPAdditionalHeaders but, did't see &nbsp;for value state of creation.</div><div class=""><br class=""></div><div class="">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.</div><div class=""><br class=""></div><div class="">anyway, HTTPAdditionalHeaders was nil. so i have to solve, and solve like this.</div><div class=""><br class=""></div><div class=""><div class="">let config = NSURLSessionConfiguration.defaultSessionConfiguration()</div><div class="">var headers = config.HTTPAdditionalHeaders ?? [NSObject: AnyObject]()</div><div class="">headers["Some-Additional-Info"] = "1992-08-01"</div></div><div class=""><br class=""></div><div class="">May be another way to solve this.</div><div class=""><br class=""></div><div class=""><b class="">so I suggest autocreate parameter or something like that</b></div><div class=""><br class=""></div><div class="">NSURLSessionConfiguration have this variable</div><div class=""><span class="gmail-s1">public</span><span class="gmail-s2"> </span><span class="gmail-s1">var</span><span class="gmail-s2"> HTTPAdditionalHeaders: [</span><span class="gmail-s3">NSObject</span><span class="gmail-s2"> : </span><span class="gmail-s3">AnyObject</span><span class="gmail-s2">]?</span><br class=""></div><div class=""><span class="gmail-s2"><br class=""></span></div><div class=""><b class="">change above things to like below</b></div><div class=""><p class="gmail-p1"><span class="gmail-s1">public</span><span class="gmail-s2">&nbsp;<b class="">autocreate</b>&nbsp;</span><span class="gmail-s1">var</span><span class="gmail-s2"> HTTPAdditionalHeaders: [</span><span class="gmail-s3">NSObject</span><span class="gmail-s2"> : </span><span class="gmail-s3">AnyObject</span><span class="gmail-s2">]? {</span></p><p class="gmail-p1"><span class="gmail-s2"><b class="">create</b> { return [NSObject: AnyObject]() }</span></p><p class="gmail-p1"><span class="gmail-s2">}</span></p><p class="gmail-p1"><span class="gmail-s2"><br class=""></span></p><p class="gmail-p1"><span class="gmail-s2">let headers = config.HTTPAdditionalHeaders must be return nil</span></p><p class="gmail-p1"><span class="gmail-s2">but&nbsp;</span></p><p class="gmail-p1">config.HTTPAdditionalHeaders["SomeThinkConvenient"] = "YEAH~"</p><p class="gmail-p1">this is automatically create Dictionary and set key and value</p><p class="gmail-p1"><br class=""></p><p class="gmail-p1">What about this idea, Dears?</p><p class="gmail-p1"><br class=""></p><p class="gmail-p1">Thank you for reading.</p></div></div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></div></div></div></div></body></html>