How to handle symlinks when reading data from a file path in swift
<p>I have a file path as a string. I want to:</p>

<ol>
<li>Test if there's a file there</li>
<li>Read the contents of the file as a string</li>
</ol>

<p>the problem I'm having is that sometimes that file path involves a symbolic link (symlink). Maybe to the file itself. Maybe to one of the directories above the file.</p>

<p>[EDIT] closing this because the following code (that I started with), actually works just fine, there were just multiple levels of user error involved. Thanks for the input folks.  </p>

<pre class="lang-swift prettyprint-override"><code>func getUserResource(relativeFilePath: String) -&gt; String? {
    let fileManager = NSFileManager.defaultManager()

    let userFilePath = NSHomeDirectory() + relativeFilePath

    if(fileManager.fileExistsAtPath(userFilePath))
    {
        do {
            return try String(contentsOfFile: userFilePath, encoding: NSUTF8StringEncoding);
        } catch {
            return nil;
        }
    }
    return nil;
}
</code></pre>