Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ios/110.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/swift/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从iOS文件应用程序(从iOS 11开始)使用iOS应用程序打开文本文件?_Ios_Swift_Openfiledialog_Uidocument - Fatal编程技术网

如何从iOS文件应用程序(从iOS 11开始)使用iOS应用程序打开文本文件?

如何从iOS文件应用程序(从iOS 11开始)使用iOS应用程序打开文本文件?,ios,swift,openfiledialog,uidocument,Ios,Swift,Openfiledialog,Uidocument,我使用Swift 4构建了一个iOS应用程序,并希望从iOS文件应用程序(自iOS 11以来)将文本文件CSV导入我的应用程序。下一步是将文本解析为json、字典或数组。这取决于内容。我只需要阅读权限 有人知道怎么做吗?我还没有找到任何教程 更新:我的问题是,如何获取并使用“打开文件对话框”来选择文本文件。我已从标题中删除了read。如果要从web服务器获取txt文件,请尝试以下操作: func download () { if let url = URL(string: "http:

我使用Swift 4构建了一个iOS应用程序,并希望从iOS文件应用程序(自iOS 11以来)将文本文件CSV导入我的应用程序。下一步是将文本解析为json、字典或数组。这取决于内容。我只需要阅读权限

有人知道怎么做吗?我还没有找到任何教程

更新:我的问题是,如何获取并使用“打开文件对话框”来选择文本文件。我已从标题中删除了read。

如果要从web服务器获取txt文件,请尝试以下操作:

func download () {

    if let url = URL(string: "http://example.com/file.txt") {
        do {
            let contents = try String(contentsOf: url)
            print(contents)
            let contentarr = contents.components(separatedBy: ";")
            print(contentarr)
        } catch {
            print("Some error happened")
        }
    } else {

print("Wrong URL")

}

你试过什么吗?添加一些代码。@Harcker感谢您的评论,但我正在寻找一种解决方案,以显示一个文件对话框来打开一个文本文件并能够读取该文件。