NSNetService dictionaryFromTXTRecord fails an assertion on invalid input
<p>The input to <code>dictionary(fromTXTRecord:)</code> comes from the network, potentially from outside the app, or even the device. However, Apple's <a href="https://developer.apple.com/reference/foundation/netservice/1408164-dictionary" rel="noreferrer" title="dictionary(fromTXTRecord:) - NSNetService">docs</a> say:</p>

<blockquote>
  <p>... Fails an assertion if txtData cannot be represented as an NSDictionary object.</p>
</blockquote>

<p>Failing an assertion leaves the programmer (me) with no way of handling the error, which seems illogic for a method that processes external data.</p>

<p>If I run this in Terminal on a Mac:</p>

<pre><code>dns-sd -R 'My Service Name' _myservice._tcp local 4567 asdf asdf
</code></pre>

<p>my app, running in an iPhone, crashes.</p>

<p><code>dictionary(fromTXTRecord:)</code> expects the TXT record data (<code>asdf asdf</code>) to be in <code>key=val</code> form. If, like above, a word doesn't contain any <code>=</code> the method won't be able to parse it and fail the assertion.</p>

<p>I see no way of solving this problem other than not using that method at all and implementing my own parsing, which feels wrong.</p>

<p>Am I missing something?</p>