简体   繁体   中英

Cannot invoke 'sequence' with an argument list of type '([AnyObject])'

I have upgraded to Xcode 7-beta and it gives me this error: Cannot invoke 'sequence' with an argument list of type '([AnyObject])'. That error is in this line of code:

sprite.runAction(SKAction.sequence(actionarray as [AnyObject]))

I found that in swift 2 I must remove part of it and it must look like this:

sprite.runAction(SKAction.sequence(actionarray))

But actionarray in NSMutableArray and now it gives me this error: Cannot invoke 'sequence' with an argument list of type '(NSMutableArray)'

This is the content of NSMutableArray:

var actionarray:NSMutableArray = NSMutableArray()
actionarray.addObject(SKAction.moveTo(CGPointMake(self.frame.size.width/2, -sprite.size.height), duration: NSTimeInterval(duration)))
actionarray.addObject(SKAction.removeFromParent())
sprite.runAction(SKAction.sequence(actionarray))

It worked well in Xcode 6. What should I change there?

Thanks

尝试使用以下语法:

SKAction.sequence(actionarray as AnyObject as [SKAction])

Why do you use NSMutableArray in Swift code in the first place? Try replacing with Swift array like this (compiles in Playground):

import Cocoa
import SpriteKit

let sprite = SKSpriteNode()
var actionarray: [SKAction] = []
actionarray.append(SKAction.moveTo(CGPointZero, duration: NSTimeInterval(1.0)))
actionarray.append(SKAction.removeFromParent())
sprite.runAction(SKAction.sequence(actionarray))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM