Cannot Convert Value of Type 'Nsmutablearray' to Expected Argument Type '[Skaction]'

Cannot convert value of type [AnyObject] to expected argument type [SKAction]

Use the Append() method.

anArray.append("This String")

Cannot convert value of type '[AnyObject]'to type 'NSArray' in coercion

Look at reverse() return type. You should cast it to Array:

var tempArr2 = Array(tempArr.reverse())

Cannot convert value of type 'String' to expected argument type 'SKNode'

The problem

You are using self before the object initialisation.

Infact writing this

let ball = childNodeWithName(BallCategoryName) as! SKSpriteNode

is equals to writing this

let ball = self.childNodeWithName(BallCategoryName) as! SKSpriteNode

But during the properties initialisation the current instance of GameScene does not exists yet! So there's no self yet.

And this is a good thing because if the compiled had allowed this code, it would have crashed at runtime since there is no ball node in you Scene yet (again because there is no Scene yet).

Solution

I suggest you to

  1. turn your stored property into a computed property
  2. use a lowercase character for the first name of a property like this ballCategoryName
  3. prefer conditional casting (as? instead of as!)
  4. turn the global constant ballCategoryName into a stored property

The code

class GameScene: SKScene {
let ballCategoryName: String = "ball"
var ball: SKSpriteNode? {
return childNodeWithName(ballCategoryName) as? SKSpriteNode
}
}

Cannot convert value of type 'Object.Type' to expected argument type 'Object'

You should refer to the current instance of Maze as self.

Notice in each example the use of the unowned or weak keywords here, to prevent a strong reference between Maze and MazeRat.

However, since self isn't available yet as rat hasn't been initialized - you need to give rat an initial value first.

Example:

class Maze {
private(set) var rat: MazeRat!

init() {
rat = nil
rat = MazeRat(maze: self)
}
}

class MazeRat {
unowned let maze: Maze

init(maze: Maze) {
self.maze = maze
}
}

Another method is to initialize MazeRat, then set the maze instance, like so:

class Maze {
let rat: MazeRat

init() {
rat = MazeRat()
rat.maze = self
}
}

class MazeRat {
weak var maze: Maze?

init() {}
}

cannot convert value of type inout CGAffineTransform to expected argument

I suggest changing your code to:

    var mirroring = CGAffineTransformMakeScale(1.0, -1.0) // flip horizontal
var mirrorPath : CGMutablePath! = CGPathCreateMutable()
CGPathAddPath(mirrorPath, &mirroring, newPath.CGPath)

let newFollow = SKAction.followPath(mirrorPath, asOffset: false, orientToPath: true, speed: 200)
player.runAction(SKAction.repeatActionForever(newFollow).reversedAction(),withKey:"followPath")

From Apple's documentation Interacting with C API's

Constant Pointers

When a function is declared as taking a UnsafePointer argument,
it can accept any of the following:

  • nil, which is passed as a null pointer.
  • An UnsafePointer,
    UnsafeMutablePointer, or AutoreleasingUnsafeMutablePointer
    value, which is converted to UnsafePointer if necessary.
  • A
    String value, if Type is Int8 or UInt8. The string will automatically
    be converted to UTF8 in a buffer, and a pointer to that buffer is
    passed to the function.
  • An inout expression whose left-hand side
    operand is of type Type, which is passed as a pointer to the address
    of the left-hand side identifier.
  • A [Type] value, which is passed as a
    pointer to the start of the array.

The 4th bullet is the one that tells us you can send &mirroring for the argument that is expecting UnsafePointer<CGAffineTransform>.

Cannot call value of non-function type '((AnyObject) - AnyObject?)!' - Swift 3

The syntax has changed from:

let x = myData.objectForKey("myKey")

to:

let x = myData.object(forKey:"myKey")

in Swift 3.

Example:

var x : AnyObject = ["Hello" : "Goodbye"] as AnyObject
x.object(forKey:"Hello")


Related Topics



Leave a reply



Submit