gpt4 book ai didi

arrays - Swift - 从文件读取/写入数组数组

转载 作者:搜寻专家 更新时间:2023-10-31 08:18:04 24 4
gpt4 key购买 nike

Here是我的文件。

我怎样才能写这个数组:

var listOfTasks = [["Hi", "Hello", "12:00"],["Hey there", "What's up?", "3:17"]]

.txt 文件 (file.txt)?我知道还有其他关于此的问题,但它们使用其他语言(不是 Swift)。我希望它能在实际的 iPhone 上运行。如有必要,我很乐意提供更多信息。我是 Swift 的新手,所以请原谅我的问题,如果它看起来太简单了。 注意:我特别询问包含数组的数组。

提前致谢!

最佳答案

已经answered youyour other question :

这是一个完整的 Playground 示例:

let fileUrl = NSURL(fileURLWithPath: "/tmp/foo.plist") // Your path here
let listOfTasks = [["Hi", "Hello", "12:00"], ["Hey there", "What's up?", "3:17"]]

// Save to file
(listOfTasks as NSArray).writeToURL(fileUrl, atomically: true)

// Read from file
let savedArray = NSArray(contentsOfURL: fileUrl) as! [[String]]

print(savedArray)

关于arrays - Swift - 从文件读取/写入数组数组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37599632/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com