作者热门文章
- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
我已将自己的 userData 添加到一组节点,并且能够检索此信息,但不知道如何以我可以使用的方式提取它。从这行代码
println(node.userData!)
我在输出控制台中得到如下形式的输出
{ 10 = 0; }
第一个数字表示整数索引值,第二个数字表示 bool 值。每个节点的索引值都不同,而所有节点的 bool 值都设置为 false。我需要在每个实例中将 bool 值更改为 true,并且我需要提取索引值以用于进一步的条件语句,例如
if indexValue = 1 {
some code here
}
我该怎么做?
最佳答案
如果要分别使用index
和boolean
值,最好将它们存储为两个键值对。
node.userData = ["index": 10, "boolean" : false ]
您可以使用以下代码提取索引。
if let index = node.userData?.valueForKey("index") as? Int {
println(index)
}
要修改你可以做的值,
node.userData?.setValue(true, forKey: "boolean")
node.userData?.setValue(11, forKey: "index")
关于swift - 如何在 Swift 中从节点中提取和修改 userData?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28845738/
我是一名优秀的程序员,十分优秀!