在Swift 3 Playground中阅读plist [英] Read plist in swift 3 playground

查看:110
本文介绍了在Swift 3 Playground中阅读plist的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里跟踪了很多问题,但似乎无济于事.

I have followed loads of questions here but nothing seems to work.

我正在Playground中使用Swift3.在El Capitan和Xcode 8.1上运行. 我有一个plist,其根为Dictionary,包含一个Int值和两个2D Int数组.

I am using Swift3 in a Playground. Running on El Capitan and Xcode 8.1. I have a plist with the root as a Dictionary containing one Int value and two 2D Arrays of Ints.

plist

我遵循的每个问题似乎都不是最有效的,因为操场不会返回错误,但似乎一直在运行(旋转图标永不停止).

Every question I follow does not seem to work the closest I have got is for the playground to not return errors but it seems to be constantly running (the spinning icon never stops).

我目前的代码,我相信这是我所获得的最接近的代码.

my current code, I believe to be the closest I have achieved.

import Foundation 
if let path = Bundle.main.path(forResource: "levelList", ofType: "plist") {
    let plistXML = FileManager.default.contents(atPath: path)!

    let mydata = try! PropertyListSerialization.propertyList(from: plistXML, options: [], format: nil) as! [String:Any]
}

在类似的情况下,我从以前的堆栈溢出尝试中尝试过的其他选项.

other options I have tried from previous stack overflow answers in a similar context.

let mydata = Dictionary(fromPropertyList: path, format: "XML") as! [String: Any]
******
let mydata = Dictionary(contentsOf: path) as? [String: Any]

数据已正确添加到资源文件夹中,因为链接的问题给出了说明. 我已经按照评论中的建议重新启动了Xcode(和mac).一段时间后,执行停止并显示错误错误:执行被中断,原因为exc_bad_access(代码= 1地址= 0x0)" 再次重新启动代码后,代码便可以正常工作了.自从操场显示的那一刻起,我将如何迅速将数据提取到数组中 ["Level 2":["Col":< _NS_array0 0x7fc620d091a0>(

The data was added to the resources folder correctly as the linked question gave instructions for. I have restarted Xcode(and mac) as suggested in the comments. After a while the execution stopped with error "error: Execution was interrupted reason exc_bad_access (code=1 address=0x0)" After another restart the code works. How do would i extract the data into an array in swift since at the moment the playground is showing ["Level 2":["Col": <_NS_array0 0x7fc620d091a0>(

推荐答案

最终使我使用的程序正常工作.

To finally get the program working I used.

devices = NSArray(contentsOfFile: path) as! [AnyObject]

运动场连续运行的问题已通过转到活动监视器并强制退出名为com.apple.coresimulator的进程来解决,该进程被确认为没有响应.完成此操作后,游乐场立即运行.

The issue with playground continuously running was solved by going to activity monitor and force quitting the process named com.apple.coresimulator which was identified as not responding. After doing this the playground ran instantly.

这篇关于在Swift 3 Playground中阅读plist的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆