Note that there are some explanatory texts on larger screens.

plurals
  1. POLoading a dictionary property list generated by the codesign tool on OS X
    text
    copied!<p>I'm working on a simple project but I've bumped up against a wall with a seemingly easy task. Loading a dictionary-rooted plist into a NSDirectory. This is something I've done plenty of times before so I'm a bit puzzled as to why I'm currently stuck.</p> <p>I'm attempting to read in a plist that I created with the codesign tool on OS X. The invocation of that tool I'm using dumps the app entitlements to a file. In the case of Safari it would do this:</p> <pre><code>codesign --display --entitlements :&lt;path to plist&gt; /Applications/Safari.app </code></pre> <p>This generates a normal XML plist at my specified path. You need the colon prefix so that it doesn't insert a magic binary blob at the beginning of the file. The full XML for the plist generated looks like this:</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt; &lt;plist version="1.0"&gt; &lt;dict&gt; &lt;key&gt;com.apple.private.accounts.allaccounts&lt;/key&gt; &lt;true/&gt; &lt;key&gt;com.apple.developer.ubiquity-kvstore-identifier&lt;/key&gt; &lt;string&gt;com.apple.Safari.SyncedTabs&lt;/string&gt; &lt;key&gt;com.apple.private.tcc.allow&lt;/key&gt; &lt;array&gt; &lt;string&gt;kTCCServiceAddressBook&lt;/string&gt; &lt;/array&gt; &lt;/dict&gt; &lt;/plist&gt; </code></pre> <p>Simple right? So now I just want to load this into a NSDictionary. I simply try to load it in the normal way:</p> <pre><code>NSDictionary *entitlementDict = [NSDictionary dictionaryWithContentsOfFile:tempFile]; </code></pre> <p>What happens though is that it refuses to load anything and I get a nil for contents:</p> <pre><code>Printing description of entitlementDict: &lt;nil&gt; (lldb) </code></pre> <p>I feel like I'm missing something obvious here. I know that the NSDictionary loading methods only work if all the contents are plist-objects, but it looks like they are and Xcode and QuickLook will happily show me the contents of the file. Additionally plutil validates that the syntax is correct.</p> <p>Any ideas? Thanks.</p> <p><strong>UPDATE:</strong></p> <p>Thanks to the folks who have answered so far. For more information I am using the proper full path.</p> <p>From the debugger:</p> <pre><code>Printing description of tempFile: /var/folders/yk/kvvzp89x03v896rqx4mc9rqw0000gq/T/FFF82FDD-0A01-4139-9719-00B447B2F907-60198-000284518B41D04F/BC54EEC8-5A0B-49FD-9BFD-44B7FFB29B73.plist </code></pre> <p>And from the terminal:</p> <pre><code>FatMan:~ macshome$ file /var/folders/yk/kvvzp89x03v896rqx4mc9rqw0000gq/T/FFF82FDD-0A01-4139-9719-00B447B2F907-60198-000284518B41D04F/BC54EEC8-5A0B-49FD-9BFD-44B7FFB29B73.plist /var/folders/yk/kvvzp89x03v896rqx4mc9rqw0000gq/T/FFF82FDD-0A01-4139-9719-00B447B2F907-60198-000284518B41D04F/BC54EEC8-5A0B-49FD-9BFD-44B7FFB29B73.plist: XML document text </code></pre> <p>and:</p> <pre><code>FatMan:~ macshome$ ls -l /var/folders/yk/kvvzp89x03v896rqx4mc9rqw0000gq/T/FFF82FDD-0A01-4139-9719-00B447B2F907-60198-000284518B41D04F/BC54EEC8-5A0B-49FD-9BFD-44B7FFB29B73.plist -rw-r--r-- 1 macshome staff 455 Jan 12 15:13 /var/folders/yk/kvvzp89x03v896rqx4mc9rqw0000gq/T/FFF82FDD-0A01-4139-9719-00B447B2F907-60198-000284518B41D04F/BC54EEC8-5A0B-49FD-9BFD-44B7FFB29B73.plist </code></pre> <p>I can post the code that generates my temp path, but I don't really think it matters much. Maybe I'll try testing with a shorter path, but I don't think that matters much either. This is a pretty typical way to generate a temp file.</p> <p><strong>Final update:</strong> I figured out what I was doing wrong, although I wish it was a more interesting answer.</p> <p>I'm calling the codesign tool with a NSTask, but in my basic testing I was forgetting to wait until it completed before attempting to load the plist into my NSDictionary. If I just use the termination handler or waitUntilExit or the termination notification then everything works as expected.</p> <p>Many thanks to those who tried to help!</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload