菜鸟教程小白 发表于 2022-12-12 08:53:59

ios - stringByExpandingTildeinPath 不可用


                                            <p><p>转换项目后,我在 Swift 2 中收到以下错误:</p>

<pre><code>stringByExpandingTildeinPath is unavailable: use stringByExpandingTildeinPath on NSString instead
</code></pre>

<p>这是我在 Swift 1.2 中用于与 whatsapp 共享的代码,第 3 行的错误:</p>

<pre><code>                let filename = &#34;myimage.wai&#34;
                let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, false) as NSString
                let destinationPath = documentsPath.stringByAppendingString(&#34;/&#34; + filename).stringByExpandingTildeInPath
</code></pre></p>
                                    <br><hr><h1><strong>Best Answer-推荐答案</ strong></h1><br>
                                            <p><p>为什么要求它不扩展<code>~</code>然后自己扩展呢?让 API 自己处理要简单得多:</p>

<pre><code>let filename = &#34;myimage.wai&#34;
let documentsPath = NSSearchPathForDirectoriesInDomains(.DocumentDirectory, .UserDomainMask, true)
let destinationPath = documentsPath + &#34;/&#34; + filename
</code></pre></p>
                                   
                                                <p style="font-size: 20px;">关于ios - stringByExpandingTildeinPath 不可用,我们在Stack Overflow上找到一个类似的问题:
                                                        <a href="https://stackoverflow.com/questions/32635314/" rel="noreferrer noopener nofollow" style="color: red;">
                                                                https://stackoverflow.com/questions/32635314/
                                                        </a>
                                                </p>
                                       
页: [1]
查看完整版本: ios - stringByExpandingTildeinPath 不可用