#39;Setlt;NSObjectgt;#39; does not have a member named #39;anyObject.quot; - Xcode 6.3(设置lt;NSObjectgt;没有名为“anyObject的成员.- Xcode 6.3)
问题描述
我正在检查是否选择了一个元素.
I'm checking to see if an element has been selected.
func touchesBegan(touches: Set<NSObject>, withEvent event: UIEvent)
{
// First, see if the game is in a paused state
if !gamePaused
{
// Declare the touched symbol and its location on the screen
let touch = touches.anyObject! as? UITouch
let location = touch.locationInNode(symbolsLayer)
这之前在 Xcode 6.2 中编译得很好,但随着 6.3 的更新,let touch = touches.anyObject!as?UITouch"这行会抛出错误:
And this had previously compiled fine in Xcode 6.2 but with a 6.3 update, the line "let touch = touches.anyObject! as? UITouch" is throwing the error:
Set"没有名为anyObject"的成员
'Set' does not have a member named 'anyObject'
我已经阅读了许多类似的问题,但我似乎无法理解要使用该值,您需要先解包"它.尤其是因为答案似乎集中在通知上.
I've read through many similar question, but I can't seem to wrap my head around "To use the value, you need to "unwrap" it first." Especially because the answers seem to focus on notifications.
非常感谢.W
推荐答案
let touch = touches.first as? UITouch
.first
可以让你访问 UITouch 的第一个对象.
.first
can allow you to access first object of UITouch.
由于 Xcode 6.3 使用 Swift (1.2) 的更新版本,您需要将旧代码转换为 Swift 1.2(编辑 -> 转换 -> 到最新的 Swift).
Since Xcode 6.3 uses an updated version of Swift (1.2) you need to convert your old code into Swift 1.2 (Edit -> convert -> To lastest Swift).
Swift 1.2,使用 Set
's(Swift 中的新功能)而不是使用 NSSet
's(Objective-C 中的旧功能).因此,touchbegan 函数也将其参数从 NSSet 更改为 Set.
Swift 1.2, uses Set
’s (new in Swift) instead of using NSSet
’s (old one in Objective-C). Thus the touchbegan function also changes its parameters from NSSet to Set.
欲了解更多信息,参考这个
这篇关于'设置<NSObject>'没有名为“anyObject"的成员.- Xcode 6.3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:'设置<NSObject>'没有名为“anyObject"的成员.- Xcode 6.3


- 如何在 iPhone 模拟器中重置 NSUserDefaults 数据? 2022-01-01
- 使用自动布局向 UIScrollView 添加动态大小的视图 2022-01-01
- URL编码Swift iOS 2022-01-01
- Xcode 7.3 中带有 UILabel 的 UIStackView 2022-01-01
- 网上有没有好的 UIScrollView 教程? 2022-01-01
- 类似于 Mail.app 的 iPad 模态视图控制器? 2022-01-01
- 在 Iphone SDK 的导航栏上添加多个按钮 2022-01-01
- GPS状态的广播接收器? 2022-01-01
- SetOnItemSelectedListener上的微调程序错误 2022-01-01
- UITextView 内容插图 2022-01-01