Swift’String.Type’没有名为’stringWithContentsOfFile’的成员

Swift’String.Type’没有名为’stringWithContentsOfFile’的成员,第1张

概述我无法从 Swift的.text文件中读取文本字符串. 我可以使用以下代码来设置文件 var writeError: NSError?let theFileToBeWritten = theStringWillBeSaved.writeToFile(pathToTheFile, atomically: true, encoding: NSUTF8StringEncoding, error: &w 我无法从 Swift的.text文件中读取文本字符串.

我可以使用以下代码来设置文件

var writeError: NSError?let thefileToBeWritten = theStringWillBeSaved.writetofile(pathToThefile,atomically: true,enCoding: NSUTF8StringEnCoding,error: &writeError);

但是每当我尝试使用“String.stringWithContentsOffile”读取文件时,我得到“’String.Type’没有名为’stringWithContentsOffile’的成员. stringWithContentsOffile也不会显示在自动完成中.

我正在使用Xcode 6.1 GM Seed 2.

我看到有人使用“stringWithContentsOffile”从许多教程和堆栈溢出文件中读取文本,但为什么它不适用于我?

尝试这样的东西:
var error:NSError?let string = String(contentsOffile: "/usr/temp.txt",enCoding:NSUTF8StringEnCoding,error: &error)if let theError = error {   print("\(theError.localizedDescription)")}

Swift 2.2:

if let string = try? String(contentsOffile: "/usr/temp.txt") {  // Do something with string}
总结

以上是内存溢出为你收集整理的Swift’String.Type’没有名为’stringWithContentsOfFile’的成员全部内容,希望文章能够帮你解决Swift’String.Type’没有名为’stringWithContentsOfFile’的成员所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1038505.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-24
下一篇 2022-05-24

发表评论

登录后才能评论

评论列表(0条)

保存