snipt

Ctrl+h for KB shortcuts

Objective-C

Get app version as NSString

NSString *version = (NSString *)CFURLCreateStringByAddingPercentEscapes(NULL,(CFStringRef)[[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"], NULL, (CFStringRef)@" !*'();:@&=+$,/?%#[]", kCFStringEncodingUTF8);
https://snipt.net/embed/249f4913bd7d6e5040158ee0a29f9394/
/raw/249f4913bd7d6e5040158ee0a29f9394/
249f4913bd7d6e5040158ee0a29f9394
objective-c
Objective-C
1
2019-06-26T17:55:28
True
False
False
/api/public/snipt/25858/
get-app-version-as-nsstring
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="bp">NSString</span> <span class="o">*</span><span class="n">version</span> <span class="o">=</span> <span class="p">(</span><span class="bp">NSString</span> <span class="o">*</span><span class="p">)</span><span class="n">CFURLCreateStringByAddingPercentEscapes</span><span class="p">(</span><span class="nb">NULL</span><span class="p">,(</span><span class="n">CFStringRef</span><span class="p">)[[</span><span class="bp">NSBundle</span> <span class="n">mainBundle</span><span class="p">]</span> <span class="nl">objectForInfoDictionaryKey</span><span class="p">:</span><span class="s">@&quot;CFBundleVersion&quot;</span><span class="p">],</span> <span class="nb">NULL</span><span class="p">,</span> <span class="p">(</span><span class="n">CFStringRef</span><span class="p">)</span><span class="s">@&quot; !*&#39;();:@&amp;=+$,/?%#[]&quot;</span><span class="p">,</span> <span class="n">kCFStringEncodingUTF8</span><span class="p">);</span> </span></pre></div> </td></tr></table>
bundle, ios, nsstring, version