<div dir="ltr">Dear swifters. <div><br></div><div>I have an proposal for autocreation of optional variables</div><div><br></div><div>This idea came from below situation</div><div><br></div><div>I have to addtional header to NSURLSessionConfiguration like this</div><div><br></div><div>let config = NSURLSessionConfiguration.defaultSessionConfiguration()</div><div>config.HTTPAdditionalHeaders?["Some-Additional-Info"] = "1992-08-01"</div><div><br></div><div>here is the problem</div><div><br></div><div>how to be sure not nil for HTTPAdditionalHeaders in defaultSessionConfiguration</div><div><br></div><div>may be nil or not nil, I read api reference of HTTPAdditionalHeaders but, did't see for value state of creation.</div><div><br></div><div>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><br></div><div>anyway, HTTPAdditionalHeaders was nil. so i have to solve, and solve like this.</div><div><br></div><div><div>let config = NSURLSessionConfiguration.defaultSessionConfiguration()</div><div>var headers = config.HTTPAdditionalHeaders ?? [NSObject: AnyObject]()</div><div>headers["Some-Additional-Info"] = "1992-08-01"</div></div><div><br></div><div>May be another way to solve this.</div><div><br></div><div><b>so I suggest autocreate parameter or something like that</b></div><div><br></div><div>NSURLSessionConfiguration have this variable</div><div><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></div><div><span class="gmail-s2"><br></span></div><div><b>change above things to like below</b></div><div>
<p class="gmail-p1"><span class="gmail-s1">public</span><span class="gmail-s2"> <b>autocreate</b> </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>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></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 </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></p><p class="gmail-p1">What about this idea, Dears?</p><p class="gmail-p1"><br></p><p class="gmail-p1">Thank you for reading.</p></div></div>