<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><div style="direction: inherit;">Thank you! I was looking for this last night and failed. </div><div style="direction: inherit;"><br></div><div style="direction: inherit;">Why do you think {public} isn't included?</div><br>Sent from my iPad</div><div><br>On Sep 3, 2016, at 2:06 PM, Ben Rimmington <<a href="mailto:me@benrimmington.com">me@benrimmington.com</a>> wrote:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html charset=utf-8"><br class=""><div><blockquote type="cite" class=""><div class="">On 3 Sep 2016, at 04:24, Brandon Knope wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">I am unsure where to post this…but iOS 10 is introducing a new API for activity tracing and logging.<div class=""><br class=""></div><div class="">The API has been “Swift-ified” a little, but it still is a little awkward to use:</div><div class=""><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" class=""><br class=""></span></div><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #3e1e81" class="">os_log</span><span style="font-variant-ligatures: no-common-ligatures" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #d12f1b" class="">"Sender: %{public}@"</span><span style="font-variant-ligatures: no-common-ligatures" class="">, log: </span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">ViewController</span><span style="font-variant-ligatures: no-common-ligatures" class="">.</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">ui_log</span><span style="font-variant-ligatures: no-common-ligatures" class="">, type: .</span><span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">debug</span><span style="font-variant-ligatures: no-common-ligatures" class="">, sender)</span></div></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class="">(This is taken from: <a href="https://developer.apple.com/library/prerelease/content/samplecode/Logging/Introduction/Intro.html#//apple_ref/doc/uid/TP40017510" class="">https://developer.apple.com/library/prerelease/content/samplecode/Logging/Introduction/Intro.html#//apple_ref/doc/uid/TP40017510</a>)</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><b class="">Note: the {public} modifier above does not work in swift but does in Objective-C. I have filed a radar for this.</b></span></div></div></div></blockquote><div><br class=""></div><div><div><i class="">Activity Tracing</i> (2014) and <i class="">Unified Logging</i> (2016) APIs are complex preprocessor macros, which are not imported into Swift.</div><div><br class=""></div><div><span class="Apple-tab-span" style="white-space:pre">        </span><<a href="https://developer.apple.com/videos/play/wwdc2014/714/" class="">https://developer.apple.com/videos/play/wwdc2014/714/</a>></div><div><br class=""></div><div><span class="Apple-tab-span" style="white-space:pre">        </span><<a href="https://developer.apple.com/videos/play/wwdc2016/721/" class="">https://developer.apple.com/videos/play/wwdc2016/721/</a>></div><div><br class=""></div><div>The <font face="Menlo" color="#78492a" class="">os_log_with_type</font> macro in <os/log.h> uses <font face="Menlo" color="#3e1e81" class="">__builtin_os_log_format</font> to encode its arguments into a byte array. The overlay for Swift instead uses its <font face="Menlo" color="#3e1e81" class="">_os_log_encode</font> C++ function, which only recognizes the <font face="Menlo" color="#d12f1b" class="">{private}</font> modifier.</div><div><br class=""></div><div><span class="Apple-tab-span" style="white-space:pre">        </span><<a href="https://github.com/apple/swift/blob/e06d676d756ce95bd7c32a3029d165c7be5fd4b4/stdlib/public/SDK/os/os.mm#L245-L255" class="">https://github.com/apple/swift/blob/e06d676d756ce95bd7c32a3029d165c7be5fd4b4/stdlib/public/SDK/os/os.mm#L245-L255</a>></div><div><br class=""></div><div><span class="Apple-tab-span" style="white-space:pre">        </span><<a href="https://github.com/apple/swift/tree/master/stdlib/public/SDK/os" class="">https://github.com/apple/swift/tree/master/stdlib/public/SDK/os</a>></div></div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><span style="font-variant-ligatures: no-common-ligatures" class="">A few things:</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class="">• This looks like how the Dispatch APIs use to look: very C-like which was made to be much better in The Great Renaming</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class="">• Cannot use Swift’s string interpolation, resulting in the arguments being passed in at the end</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><br class=""></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class="">For reference, this is what it looks like in Objective-C, showing that SOME renaming has occurred: </span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><div style="margin: 0px; font-size: 12px; line-height: normal; font-family: Menlo; color: rgb(209, 47, 27);" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #78492a" class="">os_log_debug</span><span style="font-variant-ligatures: no-common-ligatures;" class="">(</span><span style="font-variant-ligatures: no-common-ligatures; color: #4f8187" class="">ui_log</span><span style="font-variant-ligatures: no-common-ligatures;" class="">, </span><span style="font-variant-ligatures: no-common-ligatures" class="">"Sender: %{public}@"</span><span style="font-variant-ligatures: no-common-ligatures;" class="">, sender);</span></div><div class=""><br class=""></div></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class="">This might look more Swift-like:</span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><span style="color: rgb(79, 129, 135); font-family: Menlo; font-size: 12px;" class="">uiLog.</span></span><span style="color: rgb(62, 30, 129); font-family: Menlo; font-size: 12px;" class="">log(</span><span style="color: rgb(209, 47, 27); font-family: Menlo; font-size: 12px;" class="">"Sender: %{public}</span><span style="font-family: Menlo; font-size: 12px;" class="">\(sender)</span><font color="#d12f1b" face="Menlo" class=""><span style="font-size: 12px;" class="">”, </span></font><span style="font-family: Menlo; font-size: 12px; font-variant-ligatures: no-common-ligatures;" class="">type: .</span><span style="font-family: Menlo; font-size: 12px; font-variant-ligatures: no-common-ligatures; color: rgb(112, 61, 170);" class="">debug)</span></div><div class="">* Makes “log” a method on an OSLog object </div><div class="">• Uses string interpolation</div></div></div></blockquote><div><br class=""></div><div><div>The format string of <font face="Menlo" color="#78492a" class="">os_log</font> APIs is required to be constant. The overlay uses a <font face="Menlo" color="#703daa" class="">StaticString</font>, which isn't <font face="Menlo" color="#703daa" class="">ExpressibleByStringInterpolation</font>. SE-0137 also deprecated the protocol, so that it can be redesigned.</div><div><br class=""></div><div><span class="Apple-tab-span" style="white-space:pre">        </span><<a href="https://github.com/apple/swift-evolution/blob/master/proposals/0137-avoiding-lock-in.md" class="">https://github.com/apple/swift-evolution/blob/master/proposals/0137-avoiding-lock-in.md</a>></div><div><br class=""></div><div>An instance method of <font face="Menlo" color="#703daa" class="">OSLog</font> might be better, except when using the <font face="Menlo" class="">`<font color="#3e1e81" class="">default</font>`</font> object.</div><div><br class=""></div><div><span class="Apple-tab-span" style="white-space:pre">        </span><font face="Menlo" class=""><font color="#703daa" class="">OSLog</font>.<font color="#3e1e81" class="">default</font>.<font color="#3e1e81" class="">log</font>("message")</font></div><div><br class=""></div><div>Similarly, the <font face="Menlo" class=""><font color="#703daa" class="">Swift</font>.<font color="#3e1e81" class="">print</font>(<font color="#3e1e81" class="">_:separator:terminator:to:</font>)</font> function might be better as a <font face="Menlo" color="#703daa" class="">TextOutputStream</font> method.</div><div><br class=""></div><div>-- Ben</div><div class=""><br class=""></div></div></div></div></blockquote></body></html>